0% found this document useful (0 votes)
103 views

Private Constructor: Public Class Private Public Static Int Public Static Int Return

The document discusses private constructors, static constructors, HTTP handlers and modules, differences between primary and unique keys, indexes in databases, SQL joins and UNION clauses, LINQ vs stored procedures, serialization, and WCF components and bindings. A private constructor prevents instantiation of a class and is used for utility/helper classes with only static members. A static constructor initializes static members. HTTP handlers process file requests while modules run on all requests and can include custom functionality. Primary keys cannot be null and create clustered indexes, while unique keys allow nulls and use non-clustered indexes. Indexes improve data retrieval performance. LINQ supports type safety, debugging and multiple databases while stored procedures are often faster due to execution plan caching

Uploaded by

Vishal V Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Private Constructor: Public Class Private Public Static Int Public Static Int Return

The document discusses private constructors, static constructors, HTTP handlers and modules, differences between primary and unique keys, indexes in databases, SQL joins and UNION clauses, LINQ vs stored procedures, serialization, and WCF components and bindings. A private constructor prevents instantiation of a class and is used for utility/helper classes with only static members. A static constructor initializes static members. HTTP handlers process file requests while modules run on all requests and can include custom functionality. Primary keys cannot be null and create clustered indexes, while unique keys allow nulls and use non-clustered indexes. Indexes improve data retrieval performance. LINQ supports type safety, debugging and multiple databases while stored procedures are often faster due to execution plan caching

Uploaded by

Vishal V Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Private Constructor

A private constructor is a special constructor. It is commonly used in classes that contain


static members only. If all the methods in the class are static, then we use private
constructor. There are utility classes and helper class which we don’t want to create object

Private constructors are used to prevent the creation of instances of a class


A class with the private constructor cannot be inherited. Many times we don’t want to create
instance of utility class or common class

public class Counter


{
private Counter() { }
public static int currentCount;
{
public static int IncrementCount()
return ++currentCount;
}
}

class TestCounter
{
static void Main()
{
// If you uncomment the following statement, it will generate
// an error because the constructor is inaccessible:
// Counter aCounter = new Counter(); // Error

Counter.currentCount = 100;
Counter.IncrementCount();
System.Console.WriteLine("New count: {0}", Counter.currentCount);
}
}

Static Constructor
Initialization of all static members in the class we use static constructor.
When we need to assign value of static variable in class, we need to use static constructor.
When we create a class as static then it must have all the members as static.

HTTP Handlers
The Http Handler and Http Module are programs which are used by ASP.NET to handle requests based
on extensions.
Whenever the IIS Server receives a request, it looks for an ISAPI filter that is capable of handling web
requests. In ASP.NET, this is done by aspnet_isapi.dll. Same kind of process happens when an ASP.NET
page is triggered. It looks for Http Handler in the web.config files for any request setting.
The most common handler is an ASP.NET page handler that processes .aspx files. When users request an
.aspx file, the request is processed by the page handler

HTTP Modules is an assembly that is called on every request that is made to your application
and is used if we want to have our own functionality working along with the default ASP.NET
2

functionality. There is one Handler for a specific request but there could be N number of modules for
that.

Why Http Handlers


First, the Http Handlers are more reusable and portable than the normal .aspx pages. Since there are no
visual elements in an Http Handler, they can be easily placed into their own assembly and reused from
project to project. Second, Http Handlers are relatively less expensive than the Page Handler.

We will be using the built-in extensions (.ashx) that are already mapped to ASP.NET so that we can avoid
the necessity to modify the IIS extensions mapping. With .ashx extension, there is no requirement for
registration in the web/machine.config.

Difference between Primary and Unique key


Primary key cannot have null value while unique can have
We can have multiple unique key but only 1 primary key
Primary key creates clustered index while unique key non clustered key

What is an Index
Index is a database object, which can be created on one or more columns (16 Max column
combinations). The index will improve the performance of data retrieval and adds some
overhead on data modification such as create, delete and modify.

In its simplest definition a clustered index is an index that stores the actual data and a non-clustered
index is just a pointer to the data.

A clustered index is a special type of index in which the logical order of the index match the physical
stored order of the rows on disk

Composite Indexes:
A composite index is an index on two or more columns of a table.

SQL Join Types:

There are different types of joins available in SQL:

 INNER JOIN: returns rows when there is a match in both tables.

 LEFT JOIN: returns all rows from the left table, even if there are no matches in the right table.

 RIGHT JOIN: returns all rows from the right table, even if there are no matches in the left table.

 FULL JOIN: returns rows when there is a match in one of the tables.

 SELF JOIN: is used to join a table to itself, as if the table were two tables, temporarily renaming at least one
table in the SQL statement.

 CARTESIAN JOIN: returns the cartesian product of the sets of records from the two or more joined tables.

SQL UNION CLAUSE

2
3

The SQL UNION clause/operator is used to combine the results of two or more SELECT statements without returning
any duplicate rows.

To use UNION, each SELECT must have the same number of columns selected, the same number of column
expressions, the same data type, and have them in the same order but they do not have to be the same length.

The UNION ALL Clauses:


The UNION ALL operator is used to combine the results of two SELECT statements including duplicate rows.
The same rules that apply to UNION apply to the UNION ALL operator.

How Does a Non-Clustered Index Work


A table can have more than one Non-Clustered index. But, it should have only one clustered
index that works based on the Binary tree concept. Non-Clustered column always depends on the
Clustered column on the database.

Difference between Abstraction and Encapsulation


1. Abstraction means showing only methods which are necessary
2. Encapsulation means hide Complexity
MVC: Controller takes action it goes to model to fetch the data and then display on view

Boxing and Unboxing


Converting a value type to reference type is called Boxing. Unboxing is the opposite operation and is an
explicit operation.
int i = 1;
object o = i; // boxing
int j = (int) o; // unboxing

GARBAGE COLLECTION
The .NET Framework's garbage collector manages the allocation and release of memory for your
application. Each time you create a new object, the common language runtime allocates memory for the
object from the managed heap. As long as address space is available in the managed heap, the runtime
continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage
collector must perform a collection in order to free some memory.

Difference between LINQ and Stored Procedures


 Stored procedures normally are faster as they have a predictable execution plan. Therefore, if a
stored procedure is being executed for the second time, the database gets the cached execution
plan to execute the stored procedure.
 LINQ supports type safety against stored procedures. so queries errors are type checked at compile
time
 LINQ allows for debugging using .NET debugger, which is not possible in case of stored procedures.
 LINQ supports multiple databases against stored procedures which need to be re-written for
different databases.
 Deploying LINQ based solution is much simpler than a set of stored procedures. With stored
procedures, we need to provide an additional script for stored procedures but with LINQ everything
gets complied into single DLL hence deployment becomes easy

Main Advantage of LINQ


We know, it is really easy to find data from sql objects simply writing a query while its somewhat hectic
when we want to do the same thing in a DataTable or Lists.

3
4

Disadvantages of LINQ over Stored Procedures


Pre Compiled: Stored Procedures are precompiled, and LINQ queries need to compile before execution.
So stored procedures are fast in performance.

Serialization
The serialization is the process of converting the objects into stream of bytes. They are used for
transport the objects (via remoting) and persist objects (via files and databases) When developing
smaller applications that do not have a database (or other formal storage mechanism) or data that
doesn't need to be stored in a database (such as the state of a web application), you often still would
like to save the data for later retrieval. This easy way is called serialization. Serialization is the process of
storing an object, including all of its public and private fields, to a stream. Deserialization is the opposite
– restoring an object's field values from a stream.

Serialization is a process of taking an object and converting into a form so that it can be
transported across the network or can be persisted in the storage location. This storage
location can be physical file, database or ASP.NET Cache.

There are three formats of serialization


Binary Serialization : Light and compact used in Remoting
SOAP Serialization : Interoperableuse SOAP and used in web Services
XML Serialization : Custom Serialization

Difference between BasicHttpBinding and WsHttpBinding


One of the biggest differences is the security aspect. By default, BasicHttpBinding sends data
in plain text while WsHttpBinding sends it in encrypted and secured manner.
Criteria BasicHttpBinding WsHttpBinding
SOAP 1.2 and WS-Addressing
Soap version SOAP 1.1
specification.

What are the main components of WCF


The main components of WCF are as follows:
1. Service class
2. Hosting environment
3. End point

Types of Binding
 BasicHttpBinding: Basic web service communication. Exposes WCF services as legacy ASMX web
services. Used for interoperability. No security by default.
 WSHttpBinding: Web services with WS-* support. Supports transactions and reliable messaging.
 WSDualHttpBinding: Web services with duplex contract and transaction support.
 WSFederationHttpBinding: Web services with federated security. Supports transactions.
 MsmqIntegrationBinding: Communication directly with MSMQ applications. Supports transactions.
 NetMsmqBinding: Communication between WCF applications by using queuing. Supports
transactions.
 NetNamedPipeBinding: Communication between WCF applications on same computer. Supports
duplex contracts and transactions.

4
5

 NetPeerTcpBinding: Communication between computers across peer-to-peer services. Supports


duplex contracts.
 NetTcpBinding: Communication between WCF applications across computers. Supports duplex
contracts and transactions.

Difference between WEB Service and WCF Service


1 Hosting: It can be hosted in IIS It can be hosted in IIS, windows activation service, Self-hosting,
Windows service
2 Programming: [WebService] attribute has to be added to the class [ServiceContract] attribute
has to be added to the class
3 Model: [WebMethod] attribute represents the method exposed to client [OperationContract]
attribute represents the method exposed to client
4 Operation: One-way, Request-Response are the different operations supported in webservice
One-Way, Request-Response, Duplex are different type of operations supported in WCF
5 XML System.Xml.serialization name space is used for serialization System.Runtime.Serialization
namespace is used for serialization
7 Transports can be accessed through HTTP, TCP; Custom can be accessed through HTTP, TCP,
Named pipes, MSMQ, P2P, and Custom.
8 Protocols Security, Relia5 explain briefly different instance modes in WCF?

Web services can only be invoked by HTTP. While Services or a WCF component can be invoked by
any protocol and any transport type. Second web services are not flexible. However Services are
flexible. If you make a new version of the service then you need to just expose a new end. Web
service use XML Serializer while WCF use DataContractSerializer.It is new WCF serializer.
DataContractSerializer translate the .NET framework objects into XML and vice-versa.
By default WCF uses DataContractSerializer.

WCF bind an incoming message request to a particular service instance, so the available
modes are:
Per Call: instance created for each call, most efficient in term of memory but need to maintain
session.
Per Session: Instance created for a complete session of a user. Session is maintained.
Single: Only one instance created for all clients/users and shared among all. Least efficient in terms
of memory.

Explain types of security in WCF?


In WCF there are two types of Security, transport level security and message level security.

Transport Security: Transport level security is the easiest to implement. WCF uses transport protocols
like TCP, HTTP, MSMQ etc and every of these protocols have their own security mechanisms. One of
the common implementation of transport level security is HTTPS. HTTPS is implemented over HTTP
protocols with SSL providing the security mechanism. No coding change is required it’s more of
using the existing security mechanism provided by the protocol.

Message Security: Message level security is implemented with message data itself. Some of the
common ways of implementing message level security is by encrypting data using some standard
encryption algorithm.

5
6

Contracts in WCF:
The contract is a standard way of describing what the service does.
Types of Contracts:

1. Service Contract
2. Data Contract
3. Message Contract
4. Fault Contract

Message Contract
Message is the packet of data which contains important information. WCF uses these messages to
transfer information from Source to destination.

WCF uses SOAP (Simple Object Access Protocol) Message format for communication. SOAP message
contain Envelope, Header and Body. SOAP envelope contains name, namespace, header and body
element. SOAP Header contains important information which is not directly related to message.
SOAP body contains information which is used by the target.

Message Pattern

There are three way of communication between source and destination


1. Simplex - It is one way communication. Source will send message to target, but target will not
respond to the message.WCF one way contract is implemented via "IsOneWay =
true/false" attribute.
2. Request/Replay - It is two way communications, when source send message to the target, it will
resend response message to the source. But at a time only one can send a message
3. Duplex - It is two way communication, both source and target can send and receive message
simultaneously.

What is Message contract?


WCF uses SOAP message for communication.WCF provides Message Contract to customize the message
as per requirement.

Defining Message Contract


Message contract can be applied to type using MessageContract attribute. Custom Header and Body
can be included to message using 'MessageHeader' and 'MessageBodyMember' attribute. Let us see
the sample message contract definition.

[MessageContract]
public class EmployeeDetails
{
[MessageHeader]
public string EmpID;
[MessageBodyMember]
public string Name;
[MessageBodyMember]
}

6
7

When I use this EmployeeDeatils type in the service operation as parameter. WCF will add extra
header call 'EmpID' to the SOAP envelope. It also adds Name, Designation, Salary, Location as extra
member to the SOAP Body.

Fault Contract
Suppose the service I am consumed is not working in the client application. I want to know the real
cause of the problem. How I can know the error? For this we are having Fault Contract. Fault Contract
provides documented view for error occurred in the service to client. This helps us to easy identity,
what error has occurred.

Entity Framework
Entity Framework is an Object Relational Mapper (ORM). It basically generates business objects and
entities according to the database tables and provides the mechanism for:

1. Performing basic CRUD (Create, Read, Update, and Delete) operations.


2. Easily managing "1 to 1", "1 to many", and "many to many" relationships.
3. Ability to have inheritance relationships between entities.
The benefits are:
1. We can have all data access logic written in higher level languages.
2. The conceptual model can be represented in a better way by using relationships among
entities.
3. The underlying data store can be replaced without much overhead since all data access logic
is present at a higher level.

Difference between Var keyword and Datatype


Var keyword is an implicit way of defining the data type. In simple word Var keyword looks @ the
data @ right side and accordingly create datatype @ left hand
Example:
Int i=0 -> Explicitly [direct]
Var i=0->Implicitly [Indirect]

Event Bubbling
The ASP.NET page framework provides a technique called event bubbling that allows a child control
to propagate events up its containment hierarchy. Event bubbling enables events to be raised from a
more convenient location in the controls hierarchy and allows event handlers to be attached to the
original control as well as to the control that exposes the bubbled event.

Event bubbling is used by the data-bound controls (Repeater, DataList, and DataGrid) to expose
command events raised by child controls (within item templates) as top-level events.

Lambda Expression
A lambda expression is an anonymous function and it is mostly used to create delegates in LINQ.
It's shorthand that allows you to write a method without the name.

Benefits:
1. It allows you to write a method in the same place you are going to use it.

7
8

2. It is useful in places where a method is being used only once, and the method definition is short.
3. It saves you the effort of declaring and writing a separate method to the containing class.

List<int> numbers = new List<int>{11,37,52};


List<int> oddNumbers = numbers.where(n => n % 2 == 1).ToList();
//Now oddNumbers is equal to 11 and 37

Difference between stored procedure and functions

 Procedure can return zero or n values whereas function can return one value which is mandatory.
 Procedures can have input/output parameters for it whereas functions can have only input
parameters.
 Procedure allows select as well as DML statement in it whereas function allows only select statement
in it.
 Functions can be called from procedure whereas procedures cannot be called from function.
 Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used
in a function.
 Procedures cannot be utilized in a select statement whereas function can be embedded in a select
statement.
 Procedure can change or alter database but the function cannot.

What are Assemblies


An assembly is the primary building block of a .NET Framework application. It is a collection of
functionality that is built, versioned, and deployed as a single implementation unit (as one or more files).
It is a compiled code library.

Dot NET assemblies may or may not be executable, i.e., they might exist as the executable
(.exe) file or dynamic link library (DLL) file. All the .NET assemblies contain the definition of
types, versioning information for the type, meta-data, and manifest.

There are two kinds of assemblies in .NET;


 private
 shared
Private assemblies are simple and copied into private folder.

Shared assemblies (also called strong named assemblies) are copied to a single location
(usually the Global assembly cache). Hence, shared assemblies are not copied in the private
folders of each calling assembly. Each shared assembly has a four part name including its
face name, version, public key token and culture information. The public key token and
version information makes it almost impossible for two different assemblies with the same
name or for two similar assemblies with different version to mix with each other.

An assembly can be a single file or it may consist of the multiple files. Assembly is one of
the most interesting and extremely useful areas of .NET architecture along with reflections
and attributes.

GAC

8
9

Each computer where the common language runtime is installed has a machine-wide code
cache called the global assembly cache. The global assembly cache stores assemblies
specifically designated to be shared by several applications on the computer.

What is difference between server side control and client side control in asp.net?
Server-side controls like ASP:Calendar, ASP:Textbox and any other ASP-prefixed control execute on ASP
platform, on the Server and have attribute Runat=”Server”.
Client-side control are the typical HTML textboxes, textareas, etc. because those controls are rendered
(and its Javascript code is executed) in the user's browser. Client Side controls are not "directly"
accessible on code behind. You can access them with other methods.
Server Side Controls can be directly accessible from code behind.

Difference between Class and Structure in .NET


Structs are value types and classes are reference type.
Class support inheritance while Structure cannot support inheritance.
Classes have modifiers like abstract, sealed, and static while Structures can’t.
Classes can have explicitly parameter less constructors whereas structures can’t.
Member variable initialization is possible in class whereas in Structures, it is not.
It is not possible to declare destructor in structure but in class it is possible.

DIFFERENCE BETWEEN == AND EQUAL()


.Equals will actually measure the equality of the values while == will measure whether or not they are
the same reference.
object o = ".NET Interview questions";
object o1 = o;
Console.WriteLine(o == o1); True
Console.WriteLine(o.Equals(o1));True

StringBuilder s1 = new StringBuilder(“Yes”);


StringBuilder s2 = new StringBuilder(“Yes”);
Console.WriteLine(s1 == s2); False
Console.WriteLine(s1.Equals(s2)); True

Session management techniques are present in the ASP.NET framework.


In-Proc: (The Default) Session state exists within the process the web is using

SQL Server: Session data is store in the configured sql server database
 aspnet_regsql -S serverName -U UserName -P Password -ssadd -sstype p
 <sessionstate mode="SQLServer" timeout="20"
allowcustomsqldatabase="true" sqlconnectionstring="Data
Source=Server;User ID=UserID;Password=Password;" cookieless="false">

State Server: Session data is sent to the configured state server service

Difference between Value type and Reference type


Value types always contains a value while reference types can contain a null-reference, meaning that
they don't refer to anything at all at the moment

9
10

Three Tier Architecture


PL BL DL

What is the difference between Finalize() and Dispose()


Finalize () is called by Garbage Collector implicitly to free unmanaged resources. The garbage
collector calls this method at some point after there are no longer valid references to the object.
There are some resources like windows handles, database connections which cannot be collected by
the garbage collector. Therefore the programmer needs to call Dispose().
Dispose () of IDisposable interface is called by the programmer to explicitly release resources when
they are no longer being used. Dispose () can be called even if other references to the object are
alive.

State Management Technique


The ASP.NET page framework includes several state-management features to preserve page and control
values between round trips to the web server.
Client Side
State management that involve storing information either in the page or on the client computer
 View state
 Control state
 Hidden fields
 Cookies
 Query strings

Server Side
 Application state
 Session state

View State: When the page is processed, the current state of the page and controls is hashed into
a string and saved in the page as a hidden field, if the amount of data stored in the ViewState
property exceeds the specified value in the MaxPageStateFieldLength property. When the page
is posted back to the server, the page parses the view-state string at page initialization and
restores property information in the page.

Difference between application state and session state:


Session state is similar to application state, except that it is scoped to the current browser session.

Difference between View State and Control State:


ViewState and Control State are both mechanisms used in ASP.NET for maintaining data across
post backs. Both are preserved in a hidden field known as _VIEWSTATE.
The differences are:
1) ViewState can be disabled while the Control State cannot be disabled.
2) ViewState is implemented by using EnableViewState property of a control to true.
Control State works even when EnableViewState is off.

10
11

Types of authentication
ASP.NET actually supports four types of authentication:

1.Windows authentication
2.Forms authentication
3.Passport authentication
4.Anonymous access

1.Windows authentication.
If our application is targeted for use inside an organization, and users accessing the application
have existing user accounts within the local user database of the Web server or Active Directory,
you should authenticate users with Windows authentication.

2. Forms authentication
by default, Form authentication is used.
Form-based authentication presents the user with an HTML-based Web page that prompts the
user for credentials.

3. Passport authentication
you can also authenticate users using a service from Microsoft called Passport. Passport
is a centralized directory of user information that Web sites can use, in exchange for a fee, to
authenticate users.

4. Anonymous access
it will be used only by anonymous users.
<authentication mode="None" />

At which page event does the view state loaded?


ViewState is loaded between the Init() and Load() events of the page.

At which page event does the view state saved?


ViewState is loaded between the Pre-render() and Render() events of the page.

Can we have 2 methods with the same name and parameter but different return type?
Within same class it is not possible and will give an error, but one virtual function can be in base class
and we can override it or use "new" keyword in derived class with different return type.

How many cluster and non cluster index can be used in SQL?
For SQL Server 2008: 1 Clustered Index + 999 Non clustered Index = 1000 Index

Page Life Cycle


Init
Load view state
Load

11
12

Validate
Event
Pre-render
Save view state
Render
Unload
At which event we can change the master page
You can change the master page dynamically @ Pre Init event

Can we create an instance of interface and abstract class?


No, you cannot create an instance of an interface and abstract class and even if we do so it would be of
no use as none of the members in that class are implemented. Same is the case with the abstract class.
This is because they are incomplete (i.e., they act as templates) and creation of an object is not
meaningful for incomplete classes.

What is the difference between Interface and Abstract class?


In the interface all methods must be abstract.
In the abstract class some methods can be concrete.
In the interface access modifiers are not allowed.
In the abstract class modifiers are allowed.
An Interface can only inherit from another Interface.
An abstract class can inherit from a class and one or more interfaces.
An Interface cannot contain fields.
An abstract class can contain fields.
An Interface can contain property definitions.
An abstract class can implement a property.
An Interface cannot contain constructors or destructors.
An abstract class can contain constructors or destructors.
An Interface can support multiple inheritances.
An abstract class cannot support multiple inheritances.

Where to use an interface or an abstract class.

 If you anticipate creating multiple versions of your component, create an abstract class.
Abstract classes provide a simple and easy way to version your components. By updating the
base class, all inheriting classes are automatically updated with the change. Interfaces, on the
other hand, cannot be changed once created. If a new version of an interface is required, you
must create a whole new interface.
 If the functionality you are creating will be useful across a wide range of disparate objects,
use an interface. Abstract classes should be used primarily for objects that are closely related,
whereas interfaces are best suited for providing common functionality to unrelated classes.
 If you are designing small, concise bits of functionality, use interfaces. If you are designing
large functional units, use an abstract class.

12
13

 If you want to provide common, implemented functionality among all implementations of


your component, use an abstract class. Abstract classes allow you to partially implement your
class, whereas interfaces contain no implementation for any members.

What are delegates and multicast delegate?


Delegate is referred to as a type safe function pointer. Delegate is an object that can hold or refer to a
method. A delegate that refers multiple methods is called Multicast delegates

public delegate double Delegate_Prod(int a,int b);


class Class1
{
static double fn_Prodvalues(int val1,int val2)
{
return val1*val2;
}
static void Main(string[] args)
{
//Creating the Delegate Instance
Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
Console.Write("Please Enter Values");
int v1 = Int32.Parse(Console.ReadLine());
int v2 = Int32.Parse(Console.ReadLine());
//use a delegate for processing
double res = delObj(v1,v2);
Console.WriteLine ("Result :"+res);
Console.ReadLine();
}
}

Main differences between .NET 2.0, 3.0 and 3.5


.NET Framework 2. 0 Features:
• Generics
• Anonymous methods
• Partial class
• New personalization features for ASP.NET, such as support for themes,
skins and webparts.
• Data Tables

.NET Framework 3.0 Features:


• WCF
• WPF
• Windows Workflow Foundation (WF)

.NET Framework 3.5 Features:


• Language Integrated Query (LINQ) for SQL, XML, Dataset, Object
• Active directory
• ASP.NET Ajax
• Paging support for ADO.NET

.NET Framework 4.0 Features:


•Common Language Runtime (CLR) – The following sections describe new features
in security, parallel computing, performance and diagnostics, dynamic
language runtime, and other CLR-related technologies

13
14

•Base Class Libraries

Difference between Sql Server 2005 and Sql Server 2008


XML datatype is used.
Date and time are seperately used for date and time
Table datatype introduced.

Difference between Constant, static and read-only.


Constant: it's mandatory that the const keyword and must be initialized as they are declared. By
default a const is static and we cannot change the value of a const variable throughout the entire
program.
Read-only: A read only member is like a constant in that it represents an unchanging value. The
difference is that a read-only member can be initialized at runtime, in a constructor as well being able
to be initialized as they are declared.

Shadowing in C#

Difference between Response.redirect & Server.transfer


Response.Redirect involves an extra round-trip to the server whereas Server.Transfer() conserves server
resources by avoiding that extra round-trip. Server.Transfer() just changes the focus of the page by
directly communicating with server.
Round-trip - Response.Redirect() Browser pur nahee jata control first sends request for new page to
the browser, then browser sends that request to the web-server, and after that your page changes. But
Server.Transfer() directly communicate with the server to change the page hence it saves an extra
round-trip (to the browser) in the whole process.

Difference between Ref & Out Parameters


While for the Ref Parameter you need to initialize it before passing to the function and out parameter
you do not need to initialize before passing to function.

Ref (initialize the variable)


int getal = 0;
Fun_RefTest(ref getal);

Out (no need to initialize the variable)


int getal;
Fun_OutTest(out getal);

The out and the ref parameters are used to return values in the same variables, that you pass an an
argument of a method. These both parameters are very useful when your method needs to return more
than one values.

HttpContext
ASP.NET HttpContext.Current.Items allows us to hold information for a single request

Difference between IEnumerable and IQueryable


The major difference is that IEnumerable will enumerate all elements, while IQueryable will
enumerate elements based on a query. Since IQueryable executes query in SQL server with all filters.

14
15

IEnumerable<employee> emp =
dc.Employees.Where(x => x.Desc.StartsWith("soft"));
emp = emp.Take(1);

SELECT [t0].[Id], [t0].[Name], [t0].[Address], [t0].[Desc] AS [Desc]


FROM [dbo].[Employee] AS [t0]
WHERE [t0].[Desc] LIKE @p0

IQueryable<employee> emplist =
dc.Employees.Where(x => x.Desc.StartsWith("soft"));
emplist = emplist.Take(1);

SELECT TOP (1) [t0].[Id], [t0].[Name], [t0].[Address], [t0].[Desc] AS [Desc]


FROM [dbo].[Employee] AS [t0]
WHERE [t0].[Desc] LIKE @p0

Why can't you use the keyword 'this' in a static method in .Net?

"this" represents an instance of the class at runtime, so this can't be used in a static context because it
won't be referencing any instance.

1. We have two classes Base Class and child Class, Child Class inherit base class. If we make the
object of child class then which class constructor called first?
Ans: Base class constructor will be call first.
2. Can we declare an Abstract method in non-abstract class?
Ans: No
3. Can we give the return type of constructor?
Ans: No

Extension Methods: This is a new feature in C# 3.0. This method allows us to add a new static method
to the existing classes.

Partial Class: A partial class allows a single class to be divided into two separate physical files. During
compile time, these files get compiled into a single class. For instance, you can see in the below figure
we have the customer class divided into two different files “customer1.cs” and “customer2.cs”.

Using keyword in C#: It will clean up any unmanaged resources. All variables you use in Using Block get
disposed when you exit the Using Block. If you declare any un-managed object in using block, you don't
need to explicitly dispose those objects. Once the block execution is over, the Dispose will be called
automatically.

15

You might also like