Friday, January 1, 2010

.NET Mix Interview Question

How is .NET able to support multiple languages?
A language should comply with the Common Language Runtime standard to become a .NET language. In .NET, code is compiled to Microsoft Intermediate Language (MSIL for short). This is called as Managed Code. This Managed code is run in .NET environment. So after compilation to this IL the language is not a barrier. A code can call or use a function written in another language.

What is smart navigation?
The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed.

Can you have two files with the same file name in GAC ?
GAC is just a Folder that contains .dll that have strong name. We can say that GAC is a very special folder, and it is not possible two place two files with the same name into a Windows folder, But GAC differentiates by version number as well, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0.

In Assembly which work as GacBrowser?
The GACPicker class allows the user to select an assembly from the Global Assembly Cache. It does this by looking at the file system representation of the GAC, since there appears to be no actual API in the current .NET environment.

Multitasking and Multithreading
Multi tasking relates to more then one program at a same time and can switch between that programs for example:- doing work on doc file and a song is running on winamp. On the other hand multi threading is a subset of multi tasking here we can switch between different part of same program example:- doing work and .doc file and PCase is checking in background. In threading we can also set the priority of thread. some of these are as follows Thread Priority. Highest ThreadPriority.AboveNormal ThreadPriority.Normal ThreadPriority.BelowNormal ThreadPriority.Lowest

What are Daemon threads
This is a automatic thread which is stop when nothing is happening means when CPU is idle thread is also idle when CPU is doing something it will start doing for example Garbage Collector is best example for this. Syntax to make a thread Daemon Thread.IsBackground=true

How to turn off cookie in asp.net page
Use the Cookie. Discard Property which Gets or sets the discard flag set by the server. When true, this property instructs the client application not to save the Cookie on the user’s hard disk when a session ends.

How to get distinct element in array
 Let suppose my array contains {3, 8, 8, 8, 15, 15} int[] arr = { 3, 8, 8, 15, 15 }; System.Collections.IEnumerable a = arr. Distinct ();

SQL Server and ASP.NET performance tips
Always use same connection string to get advantage of Connection pooling.Becuase connection polling is not used for new connection. Always close user-defined transactions before closing a connection. Close your connection as soon as you are done using it. Do leave a connection open if it is not used. Always drop temporary objects before closing a connection. Open connection when on need not before the need.

 What is the fastest way to concat strings in ASP.NET
By Using Append method of the String Builder object we can concat string in ASP.NET

Difference between System exception and Application exceptions
 In asp.net all the exceptions comes from Exception Base class. We can also generate custom exception. Application Exception are the system base which serves as the base class for all applications related exception. It derives from Exception but we cannot extend its functionality. We should derive our custom application exceptions from Application Exception. Application exception is used when we want to define user defined exception, while system exception is all which is defined by .NET.

Explain Generic Class and its advantage ?
From the Generic class single class can be used by number of client which reduce the cost and risk. There are number of features included in Generic class it is reusable, type safety, and performance. We can also create our own interface, class and delegates. We can get the garlic data type at runtime by the use of reflection.Generic class comes in System.Collections.generic namepace.The main advantage of generics is to create collection classes.

What is cross page posting in ASP.NET2.0
When we have to post data from one page to another in application we used server. Transfer method but in this the URL remains the same but in cross page posting there is little different there is normal post back is done but in target page we can access values of server control in the source page. This is quite simple we have to only set the PostBackUrl property of Button,LinkButton or image button which specifies the target page. In target page we can access The Previous Page property. And we have to use the @PreviousPageType directive. We can access control of Previous Page by using the find control method. When we set the PostBackUrl property ASP.NET framework bind the HTML and JavaScript function automatically.

What is the purpose of IIS
We can call IIS(Internet Information Services) a powerful Web server that helps us creating highly reliable, scalable and manageable infrastructure for Web application which runs on Windows Server 2003. IIS helps development center and increase Web site and application availability while lowering system administration costs. It also runs on Windows NT/2000 platforms and also for above versions. With IIS, Microsoft includes a set of programs for building and administering Web sites, a search engine, and support for writing Web-based applications that access database. IIS also called http server since it process the http request and gets http response.

What is different between WebUserControl and in WebCustomControl Web user controls ?
Web User Control is Easier to create and another thing is that its support is limited for users who use a visual design tool one good thing is that its contains static layout one more thing a separate copy is required for each application. Web custom controls:-Web Custom Control is typical to create and good for dynamic layout and another thing is it have full tool support for user and a single copy of control is required because it Is placed in Global Assembly cache.

What is Sandbox in SQL server and explain permission level in Sql Server
Sandbox is place where we run trusted program or script which is created from the third party. There are three type of Sandbox where user codes run. Safe Access Sandbox:-Here we can only create stored procedure,triggers,functions,datatypes etc.But we does not have access memory ,disk etc. External Access Sandbox:-We can access File systems outside the box. We can not play with threading, memory allocation etc. Unsafe Access Sandbox:-Here we can write unreliable and unsafe code.

How many types of cookies are there in .NET
 Two type of cookies.
a) Single valued e.g. request. Cookies(?Username?).Value=?dotnetquestion?
b)Multivalued cookies.
 These are used in the way collections are used example Request. Cookies(?CookiName?)(?Username?)=?dotnetquestionMahesh? Request. Cookies(?CookiName?)(?UserID?)=?interview″

When we get Error HTTP 502 Proxy Error
We get this error when we execute ASP.NET Web pages in Visual Web Developer Web server, because the URL randomly select port number and proxy servers did not recognize the URL and return this error. To resolve this problem we have to change settings in Internet Explorer to bypass the proxy server for local addresses, so that the request is not sent to the proxy.

What do you mean by three tier architecture
The three-tier architecture was comes into existence to improve management of code and contents and to improve the performance of the web based applications. There are mainly three layers in three-tier architecture. They are define as follows
 (1)Presentation
 (2)Business Logic
 (3)Database

 (1)First layer Presentation contains mainly the interface code, and this is shown to user. This code could contain any technology That can be used on the client side like HTML, JavaScript or VBScript etc.
 (2)Second layer is Business Logic which contains all the code of the server-side .This layer have code to interact with database and to query, manipulate, pass data to user interface and handle any input from the UI as well.
(3)Third layer Data represents the data store like MS Access, SQL Server, an XML file, an Excel file or even a text file containing data also some additional database are also added too that layers.

What is Finalizer in .NET define Dispose and Finalize
We can say that Finalizer is the method that's helps in cleanup the code that is executed before object is garbage collected .The process is called finalization . There are two methods of Finalizer :-
Dispose
Finalize .

There is little different between two of this method . When we call Dispose method is release all the resources hold by an object as well as all the resources hold by the parent object. When we call Dispose method it clean managed as well as Unmanaged resources.
Finalize method also cleans resources but finalize call dispose clears only the unmanaged resources because in finalization the garbage collector clears all the object hold by managed code so finalization fails to prevent those one of method is used that is: GC.SuppressFinalize.

Define SMTPclient class in Dot Net framework class library
Each classes in dot net framework include some properties, method and events. These properties ,methods and events are member of a class. SMTPclient class mainly concern with sending mail. This class contains the following member. Properties:- Host:-The name or IP address of email server. Port:-Port that is use when sending mail. Methods:- Send:-Enables us to send email synchronously. Send Asynchronous:-Enables us to send an email asynchronously. Event:- Send Completed:-This event raised when an asynchronous send operation completes.

What is late binding
When code interacts with an object dynamically at runtime .because our code literally does not care what type of object it is interacting and with the methods that are supported by object and with the methods that are supported by object .The type of object is not known by the IDE or compiler ,no Intellisense nor compile-time syntax checking is possible but we get unprecedented flexibility in exchange. If we enable strict type checking by using option strict T on at the top of our code modules ,then IDE and compiler will enforce early binding behavior .By default Late binding is done.

Does .NET CLR and SQL SERVER run in different process
Dot Net CLR and all .net relates application and Sql Server run in same process or we can say that that on the same address because there is no issue of speed because if these two process are run in different process then there may be a speed issue created one process goes fast and other slow may create the problem.

What is Com Marshler and its importance in .NET
Com Marshler is one of useful component of CLR. Its Task is to marshal data between Managed and Unmanaged environment .It helps in representation of data across different execution enviroment.It performs the conversion of data format between manage and unmanaged code. By the helps of Com Marshler CLR allows manage code to interoperate with unmanaged code. The IHttpHandler and IHttpHandlerFactory interfaces The IHttpHandler interface is implemented by all the handlers. The interface consists of one property called Is Reusable. The Is Reusable property gets a value indicating whether another request can use the IHttpHandler instance. The method Process Request() allows you to process the current request. This is the core place where all your code goes. This method receives a parameter of type Http Context using which you can access the intrinsic objects such as Request and Response. The IHttpHandlerFactory interface consists of two methods - Get Handler and Release Handler. The Get Handler() method instantiates the required HTTP handler based on some condition and returns it back to ASP.NET. The Release Handler() method allows the factory to reuse an existing handler.

 What is Satellite Assemblies ?
Satellite assemblies are often used to deploy language-specific resources for an application. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language. When uninstalling, the application removes only the satellite assemblies associated with a given language and .NET Framework version. No core . NET Framework files are removed unless the last language for that .NET Framework version is being removed. For example, English and Japanese editions of the .NET Framework version 1.1 share the same core files. The Japanese .NET Framework version 1.1 adds satellite assemblies with localized resources in a \ja subdirectory. An application that supports the .NET Framework version 1.1, regardless of its language, always uses the same core runtime files.

 What is CAS CAS?
CAS is the part of the .NET security model that determines whether or not a piece of code is allowed to run, and what resources it can use when it is running. For example, it is CAS that will prevent a .NET web applet from formatting your hard disk. How does CAS work? The CAS security policy revolves around two key concepts - code groups and permissions. Each .NET assembly is a member of a particular code group, and each code group is granted the permissions specified in a named permission set. For example, using the default security policy, a control downloaded from a web site belongs to the 'Zone - Internet' code group, which adheres to the permissions defined by the 'Internet' named permission set. (Naturally the 'Internet' named permission set represents a very restrictive range of permissions.)

Automatic Memory Management
Automatic Memory Management: From a programmer's perspective, this is probably the single biggest benefit of the .NET Framework. No, I'm not kidding. Every project I've worked on in my long career of DOS and Windows development has suffered at some point from memory management issues. Proper memory management is hard. Even very good programmers have difficulty with it. It's entirely too easy for a small mistake to cause a program to chew up memory and crash, sometimes bringing the operating system to a seacrching halt in the process.
Programmers understand that they're responsible for releasing any memory that they allocate, but they're not very good at actually doing it. In addition, functions that allocate memory as a side effect abound in the Windows API and in the C runtime library. It's nearly impossible for a programmer to know all of the rules. Even when the programmer follows the rules, a small memory leak in a support library can cause big problems if called enough.
The .NET Framework solves the memory management problems by implementing a garbage collector that can keep track of allocated memory references and release the memory when it is no longer referenced. A large part of what makes this possible is the blazing speed of today's processors. When you're running a 2 GHz machine, it's easy to spare a few cycles for memory management. Not that the garbage collector takes a huge number of cycles--it's incredibly efficient. The garbage collector isn't perfect and it doesn't solve the problem of mis-managing other scarce resources (file handles, for example), but it relieves programmers from having to worry about a huge source of bugs that trips almost everybody up in other programming environments. On balance, automatic memory management is a huge win in almost every situation.

What is Sealed class
 A class can be made sealed in c# using the sealed keyword. When you do that, it implies that the class cannot be inherited. You can extend this functionality to the individual methods as well. In case you want a class to be inherited, excluding one of its methods, just make that particular method sealed.

What the New features are added to C sharp 3.0 over C sharp 2.0 ?
These are the major new enhancements expected in C# 3.0:-
* Implicitly typed local variables
* Anonymous types
 * Extension methods
* Object and collection initializers
 * Lambda expressions
* Query expressions
* Expression Trees

What the relation between Static method in Interface ?
Static methods are common in class. In object oriented , an interface is not technically a class, it is a type, but not a class so interfaces do not extend Object. Because interfaces are not classes, they cannot have static methods, because there is no actual class to attach to. We may call InterfaceName.class to get the Class Object corresponding to the interface, but the Class specifically states that it represents classes and interfaces in a object oriented application. However, the interface itself is not treated as a class, and hence you cannot attach a static method.

 What is Generic class how it helps programmer?
 Generic is new feature included in .NET it is essential in C# .Because today the projects are more complicated as past so programmer badly need to use better reuse and customize their existing component-based software. So get this high level of code reuse in other languages, programmers have a option that option is Generics .By Using Generics, we can create class templates that support any type.

 What is the use of USING in c sharp ?
As we all knows that one of beauty of C# is that it will releases memory automatically and in .NET CLR do this work calling garbage collector release object that are not needed. USING is also play some role in releasing memory its programmer to specify which object should release that using resources. When object is provided to Using statement it must provided a iDisposable interface. This interface contains Dispose method.

What is Partial class ?
Partial class can also be split into two or more classes. We can also say that a class be physically separated into other parts of the class but within the same namespace and also one more important thing the parts must use the partial keyword. And other classes should also have the same access modifier. When compile is done, all the partial classes will be treated as a single class. Let us list some advantages of having partial classes.
? Allows a clean Separation of business logic layer and the user interface.
? The UI code can be hidden from the developer.
? Makes the debugging easier.

What are the Hiding method in c sharp can it is possible to hide method without using Virtual Function ?
It is possible to hide the base class method with the derived class without using Virtual in base class and Override keyword in subclass. There are some condition where we have to redefine any method in derived class same name in base class now question arise how can we hide the method answer is simple and logical we use the modifier NEW which tell the compiler that derived class method "hides the base class method. There are some example:
Class baseless s
{
 Public void display()
 {
 console.writeline("base method");
}
}

class derived : base class
{
 public new void display()
{
 console.writeline("derived method");
 }
}

 class test
{
 public static void main()
{
derived d=new derived class();
 d.display();
}
}

Explain some of method of System. Array class
Clear():-Set ranges of value to empty.
Copy To():-Copies element source to destinations.
Get Length()-:Display number of element in given array.
 Get Value():-Value of given index in array.
Length():-To get length of array.
Set Value():-Sets the value of given index in the array.
Reverse() :-Reverse the element of Array.
Sort():-Sort the element in array.

Is there an equivalent of exit for quitting a C sharp.NET application
Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application. Exit() if it’s a Windows Forms app.

Is there a way to force garbage collection ?
Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn’t seem to be doing it for you, you can force Finalizer to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().

Are private class level variables inherited ?
Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited.

 What is the difference between the C sharp.NET and VB.NET ?VB.NET



It didn't have the XML Documentation.
- It didn't have the Operator Overloading.
 - It didn't have the Pointer Type variables.
 
 C#.NET -
It has XML Documentation, Operator Overloading and supports Pointer Variables using unsafe keyword.
 
How to get total no of control on a particular page ?
foreach (Control ctl in Page.Controls[1].Controls )
{
Textbox tb = ctl as Textbox;
if (tb!=null) { tb. Text = "" ;
}
}
 
 What optimizations does the C sharp compiler perform when you use the optimize plus compiler option ?
The following is a response from a developer on the C# compiler team: We get rid of unused locals (i.e., locals that are never read, even if assigned). We get rid of unreachable code. We get rid of try-catch with an empty try. We get rid of try-finally with an empty try. We get rid of try-finally with an empty finally. We optimize branches over branches: gotoif A, lab1 goto lab2: lab1: turns into: gotoif !A, lab2 lab1: We optimize branches to ret, branches to next instruction, and branches to branches.
 
 Define different namespaces in ado.net for data provide .
System.data:-Its contains some basic objects for relational data just like dataset,datatable and data relation.

System.Data.OleDB:-Its main function is to help in connecting with data with OLE-DB provider.

System.Data.SqlClient:-Its main function is to help in connecting with TDS interface and provide better performance.
System.XML:-Its helps in basic objects method to create, read, store, write, and manipulate XML documents

What is Asynchronous Database Commands ?
When we execute any database. Thread that executing the command waits before the command get fully executing before executing any additional code. Thread is blocked for another process. But Asynchronous Database Commands solve this problem when database command is executing the current thread can continue on other process. Thread can execute a no of database command. There are two benefits of using Asynchronous Database Commands.
1) Executing Multiple Database Commands simultaneously improve performance.
2) Because ASP.Net framework uses a limited pool service for request. When any request for a page is comes its assign a thread to handle the request. If framework is out of thread then job is in guesses we get error 503. But if we are using asynchronous database command then current thread is release back to current thread pool.

What is Concurrency and its types?
When two or more people try to update same type of data then Concurrency helps how to handle this situation there are two types of concurrency Pessimistic:-When one user try to change the data with pessimistic concurrency a lock is placed on the data so that another user cannot change that one after one another can change. Optimistic:-In this if two user works on the same data and one change that data first then second user cannot change that same data because the which he have using is already changed so he cannot do the change because change apply to another data that is changed by first user.

Which should be prefer in which condition Dataset and Data Reader
The data reader is helpful when we have number of tables and large query too and database in non-uniform pattern and we need not execute the large no. of queries on few particular table. On the other hand when we have low number of table and most of the time you need to execute queries on these fewer tables, we should go for the dataset.

What do you mean by Attributes and Reflection
Attributes is a techniques for adding metadata, just like compiler instructions and other data about your data, methods, and classes, to the program itself. Attributes are inserted into the metadata and are visible through ILDasm and other metadata-reading tools. Reflection is the process from which a program can read metadata that of its own. A program is said to reflect on itself, extracting metadata from its assembly and using that metadata either to in form the user or to modify its own behavior.

What is a command object in ADO.NET and Type of command object
ADO.NET recognizes three types of commands.
 The first type is text commands, which are those text commands that are sent to the database server directly and written in specific SQL Dialect (for SQL Server, MSDE and Access it's T-SQL).
The commandType.Text is the default for the property CommandType of the Command object.

 The second type is the CommandType.StoredProcedure which is set to call a specific stored procedure in the database; of course when you set the Command.CommandType property to CommandType.StoredProcedure, the value of the Command.CommandText must be the name of the stored procedure that you are calling.

Finally, the type CommandType.TableDirect is used to return a complete table from the database, and it's used only by the OLEDB .NET Data Provider.

What is MARS support in ADO.NET ?
In First version of ADO.NET we only do is one connection on one result set. But the new feature allow us to do multiple commands on the same connection. And another feature is we can switch back and forth in command objects in connection. MARS means(Multiple Active Result Sets).

 How to get database schema information when connection object is establish in ADO.NET
There is a method that helps in getting schema information that is GetSchema() and this method is called in three different ways first way when we call this method without any parameter its return the metadata(table, view, stored procedure. Indexes etc).When method is called by passing metadata collection name and filter criteria returns the items from the collection after applying the filter criteria and last way is when we called by passing a metadata collection name returns information about items found in the specified collection.

Some important instruction regarding ADO.NET connection string
When we are making connection string always use Server's IP address not the DNS name if we use IP address it will reduce the time taken for connection to establish.Becasue server IP address is used to get a default or named instance of Sql Server that ls running. if we are running the cluster we have to use the Virtual SQL Server IP address.

What is Ref Cursor in .NET and how it is link with ExecuteReader?
 Ref cursor play its role when doing with the oracle database these comes in ODP.NET. Ref Cursors are objects that link to Oracle server-side cursors. These Ref Cursor can be converted in oracle datareader with this Ref cursor we can get result with query written to pl/sql and the result can be get in .net. Now the question arise why we use Ref Cursor when we have an option of ExceuteReader reason is simple when we need more query in pl/sql means our work is d one in pl/sql then we need this ref cursor for getting result set because does not have direct connection to that table.Becasue advantage of pl/sql we can take two operation in one query.

How to get result from two table in Sql Datareader?
 string str="Select * from table1;Select * from table2"; cmd.commandtext=str; dr=cmd.executereader();

Define different execute methods of ADO.NET command object
ExecuteScalar:- This method returns a single value from the first row and first column of the result get from the execution of SQL query.

ExecuteNonQuery:- This method executes the DML SQL query just like insert, delete or update and then returns the number of rows affected by the action.

ExecuteReader:- This method returns Datareader object which is a forward-only resultset.

ExecuteXMLReader:- This method is available for SQL Server 2000 or later. Upon execution it builds XMLReader object from standard SQL query.

Is XML is a component of ADO.NET?
Yes ,because XML is an important component of ADO.NET architecture .ADO.NET use XML to store and transfer data. We not have to convert data to XML format. Datasets helps XML to integrate with ADO.NET. XML schema plays a role to get table definition,column,datatypes and constraints helps Dataset.

How to check if the Dataset has records
If ds.Tables(0).Rows.Count= 0 then
 'No record
else 'record found

What is the significance of CommandBehavior.CloseConnection?
To avoid having to explicitly close the connection associated with the command used to create either a Sql Datareader or and OleDbDataReader, pass the CommandBehavior.CloseConnection argument to the ExecuteReader method of the Connection.
dr= cmd.ExecuteReader(CommandBehavior.CloseConnection);
The associated connection will be closed automatically when the Close method of the Datareader is called. This makes it all the more important to always remember to call Close on your datareader.

Which method do you invoke on the Data Adapter control to load your generated dataset with data
The Fill() method.

 What is Dataset and Diffgram ?
When sending and retrieving a Dataset from an XML Web service, the Diffgram format is implicitly used. Additionally, when loading the contents of a Dataset from XML using the ReadXml method, or when writing the contents of a Dataset in XML using the WriteXml method, you can select that the contents be read or written as a Diffgram. For more information, see Loading a Dataset from XML and Writing a Dataset as XML Data. While the Diffgram format is primarily used by the .NET Framework as a serialization format for the contents of a Dataset, you can also use DiffGram to modify data in tables in a Microsoft SQL Server? 2000 database.

 What is typed dataset?
 A typed dataset is very much similar to a normal dataset. But the only difference is that the schema is already present for the same. Hence any mismatch in the column will generate compile time errors rather than runtime error as in the case of normal dataset. Also accessing the column value is much easier than the normal dataset as the column definition will be available in the schema.

What are the differences between Datalist DataGrid and datarepeater?
DataList 
*Has table appearance by default
* Has no auto format option
* has no default paging & sorting options
* can define separators between elements using template

DataGrid
 * Has a grid appearance by default
* has a auto format option
* has default paging and sorting
* has no separator between elements DataRepeater
* simple, read-only output, has no built in support for selecting or editing items, has no DEFAULT APPEARENCE, has no default paging.