What is the new data type in C# 4.0?

December 29, 2010

C# 4.0 adds a new data type called dynamic, which causes type checking to be deferred until runtime, rather than occurring at compile time. Thus, the dynamic type is an exception to C#’s normal compile-time type checking.

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.

Scope modifiers in .NET

December 27, 2010

The .NET environment includes the following scope modifiers: public, internal, protected, internal protected, and private. Not all scope modifiers can be used at all times. When declaring types, only the modifiers public and internal can be used. All scope modifiers can be used when declaring methods or data members belonging to a type.

Following are the different types of scope modifiers:

§ public: Defines a type, method, or data member to be considered visible regardless of assembly or program scope. The public scope modifier is considered the loosest of scope modifiers, and therefore the most dangerous with respect to managing unwanted references.

§ internal: Defines a type, method, or data member that has a public scope in the context of an assembly. The type, method, or data member cannot be accessed from outside the assembly.

§ protected: Protected methods and data members are scoped as private by any code that attempts to use the method or data type directly. If the method or data member is called from a subclassed type, then the scope is more akin to public. For quick reference, protected means public or private scope depending on the context.

§ internal protected: This protection can only be applied to methods or data members, and is a combination of the internal and protected scope modifiers. This means a method or data member has public scope in the subclassed type.

§ private: Defines a method or data member that’s private and only accessible to the type defining the method or data member.

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.

What is enableViewStateMac?

December 9, 2009

Its an Optional Boolean attribute of page directives.

enableViewStateMac Specifies whether ASP.NET should run a message authentication code (MAC) on the view state for the page when the page is posted back from the client. If True, the encrypted view state is checked to verify that it has not been tampered with on the client.

The default is True.

Note: For more Page Directive attributes check this link http://msdn.microsoft.com/en-us/library/950xf363.aspx

What is SOAP?

December 8, 2009

Definition:

SOAP is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. SOAP uses XML technologies to define an extensible messaging framework, which provides a message construct that can be exchanged over a variety of underlying protocols. The framework has been designed to be independent of any particular programming model and other implementation specific semantics.(Definition from SOAP 1.2 specification)

Structure of a SOAP Envelope:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header> <!-- optional -->
    <!-- header blocks go here... -->
  </soap:Header>
  <soap:Body>
    <!-- payload or Fault element goes here... --> 
  </soap:Body>
</soap:Envelope>

Note: As of the SOAP 1.2 spec, SOAP is no longer an acronym at all. See the note at the bottom of the introduction section: http://www.w3.org/TR/soap12-part1/#intro

If your webmethod is having return type is void and while consuming the webservices you don’t want to wait the complete execution of that method. How would you achieve this?

December 8, 2009

Its possible by setting OneWay property to "True" in SoapDocumentMethod or SoapRpcMethod.

Example:

<%@ WebService Language="C#" Class="Stats" %>

using System.Web.Services;

using System.Web.Services.Protocols;

public class Stats: WebService {

[ SoapDocumentMethod(OneWay=true) ]
[ WebMethod(Description="Starts nightly statistics batch process.") ]

public void StartStatsCrunch() {
// Begin nightly statistics crunching process.
// A one-way method cannot have return values.
}

}

Explanation:

SoapDocumentMethodAttribute.OneWay Property Gets or sets whether an XML Web service client waits for the Web server to finish processing an XML Web service method.The possible property value is True or False.

Modes of Session State?

November 23, 2009

Three Modes of Session State Is available In Asp.net

InProc Mode – The session State is stored In the Memory of the local where ASPnet_Wp.exe Process is runnning.When we Restart the application or reboot the IIS , the session state is lost

State Server – The session state is serialized and stored in a Seperate Process (ASPnet_state.exe).It can be stored on a Seperate system If needed.

Sql Server– The session State is Serialized and Stored in the Sql Server Database
.

Abstract Class versus Interface

November 19, 2009

 

Feature Interface Abstract class
Multiple inheritance A class may inherit several interfaces. A class may inherit only one abstract class.
Default implementation An interface cannot provide any code, just the signature. An abstract class can provide complete, default code and/or just the details that have to be overridden.
Access Modfiers An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public An abstract class can contain access modifiers for the subs, functions, properties
Core VS Peripheral Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface. An abstract class defines the core identity of a class and there it is used for objects of the same type.
Homogeneity If various implementations only share method signatures then it is better to use Interfaces. If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Speed Requires more time to find the actual method in the corresponding classes. Fast
Adding functionality (Versioning) If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Fields and Constants No fields can be defined in interfaces An abstract class can have fields and constrants defined

 

For clear explanation with example, Check the link

http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx

How to implement JOIN on ntext, text, or image columns?

November 6, 2009

Tables cannot be joined directly on ntext, text, or image columns. However, tables can be joined indirectly on ntext, text,or image columns by using SUBSTRING.

For example,

SELECT * FROM t1 JOIN t2 ON SUBSTRING(t1.textcolumn, 1, 20) = SUBSTRING(t2.textcolumn, 1, 20)

performs a two-table inner join on the first 20 characters of each text column in tables t1 and t2. In addition, another possibility for comparing ntext or text columns from two tables is to compare the lengths of the columns with a WHERE clause, for example (where a self-join is performed on the pub_info table):

WHERE DATALENGTH(p1.pr_info) = DATALENGTH(p2.pr_info)

Is uniqueidentifier column must have UNIQUE values?

November 6, 2009

No, uniqueidentifier columns may contain multiple occurrences of an individual uniqueidentifier value, unless the UNIQUE or PRIMARY KEY constraints are also specified for the column. A foreign key column that references a uniqueidentifier primary key in another table will have multiple occurrences of individual uniqueidentifier values when multiple rows reference the same primary key in the source table.

Difference between inner join and outer join?

November 2, 2009

Inner join : An inner join (sometimes called a simple join ) is a
join of two or more tables that returns only those rows that satisfy the join condition.

Outer Joins : An outer join extends the result of a simple join. An outer
join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition