Saturday 7 December 2013

Dot Net Interview Questions And Answers For Experienced

Please find the below interview questions and answers for experienced dot net professionals.

1. difference between "is" and "as" in c#

 "as" operator is used to perform conversions between compatible type   whereas "is" operator
checks if an object is compatible with a given type.

2. Difference between convert.tostring() and .tostring()

convert.tostring() supports null whereas .tostring() will not support null

3. Jump statement in C#

break, continue, goto, return, throw

4. C# Escape character for Null

\0

5. How to assign a value to a readonly variable in C#

using constructor

6. Example of Parameterized datatypes in C#

Generics. Example: List<String>

7. Delegates are typically used in C# to implement what design pattern?

Publish/Subscrible

8. Can an abstract class be declared as sealed?

No

9. Use of Var keyword supported in C# from which version of .net?
3.0
10. Access specifiers in C#
Public, Private, Protected, internal, protected internal
11. Does C# support static indexers?
No. It supports only instance indexers.
12. Can we put a break statement in a finally block?
No.
13. Which method would be used to invoke a delegate type asynchronously in c#?
BeginInvoke()
14. What is the extension of multifile assembly?
.netmodule
15. What is dynamic binding in .net?
The method called is determined based on the runtime type of the object
16. What is reflection?
All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection.
The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly.
Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes -
e.g. determining data type sizes for marshaling data across context/process/machine boundaries.
Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember), or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).
17. What size is a .NET object?
Each instance of a reference type has two fields maintained by the runtime - a method table pointer and a sync block. These are 4 bytes each on a 32-bit system, making a total of 8 bytes per object overhead. Obviously the instance data for the type must be added to this to get the overall size of the object. So, for example, instances of the following class are 12 bytes each:
class MyInt
{
...
private int x;
}
However, note that with the current implementation of the CLR there seems to be a minimum object size of 12 bytes, even for classes with no data (e.g. System.Object).
Values types have no equivalent overhead.
18. What is the difference between an event and a delegate?
An event is just a wrapper for a multicast delegate. Adding a public event to a class is almost the same as adding a public multicast delegate field. In both cases, subscriber objects can register for notifications, and in both cases the publisher object can send notifications to the subscribers. However, a public multicast delegate has the undesirable property that external objects can invoke the delegate, something we''d normally want to restrict to the publisher.
Hence events - an event adds public methods to the containing class to add and remove receivers, but does not make the invocation mechanism public.
19. How does .NET remoting work?
.NET remoting involves sending messages along channels. Two of the standard channels are HTTP and TCP. TCP is intended for LANs only - HTTP can be used for LANs or WANs (internet).
Support is provided for multiple message serializarion formats. Examples are SOAP (XML-based) and binary. By default, the HTTP channel uses SOAP (via the .NET runtime Serialization SOAP Formatter), and the TCP channel uses binary (via the .NET runtime Serialization Binary Formatter). But either channel can use either serialization format.
There are a number of styles of remote access:
SingleCall. Each incoming request from a client is serviced by a new object. The object is thrown away when the request has finished.
Singleton. All incoming requests from clients are processed by a single server object.
Client-activated object. This is the old stateful (D)COM model whereby the client receives a reference to the remote object and holds that reference (thus keeping the remote object alive)
until it is finished with it.
Distributed garbage collection of objects is managed by a system called ''leased based lifetime''.
Each object has a lease time, and when that time expires the object is disconnected from the .NET runtime remoting infrastructure. Objects have a default renew time - the lease is renewed when a successful call is made from the client to the object. The client can also explicitly renew the lease.
20. How do I prevent concurrent access to my data?
Each object has a concurrency lock (critical section) associated with it. The
System.Threading.Monitor.Enter/Exit methods are used to acquire and release this lock. For example, instances of the following class only allow one thread at a time to enter method f():
class C
{
public void f()
{
try
{Monitor.Enter(this);
...

}
finally
{
Monitor.Exit(this);
}
}
}

C# has a ''lock'' keyword which provides a convenient shorthand for the code above:
class C
{
public void f()
{
lock(this)
{
...
}
}
}

Note that calling Monitor.Enter(myObject) does NOT mean that all access to myObject is serialized. It means that the synchronisation lock associated with myObject has been acquired, and no other thread can acquire that lock until Monitor.Exit(o) is called. In other words, this
class is functionally equivalent to the classes above:
class C
{
public void f()
{
lock( m_object )
{
...
}
}


private m_object = new object();
}
Actually, it could be argued that this version of the code is superior, as the lock is totally encapsulated within the class, and not accessible to the user of the object.
21. How can I stop my code being reverse-engineered from IL?
You can buy an IL obfuscation tool. These tools work by ''optimising'' the IL in such a way that reverse-engineering becomes much more difficult.
Of course if you are writing web services then reverse-engineering is not a problem as clients do not have access to your IL.
22. What is Fragment Caching in ASP.NET?
> Fragment caching refers to the caching of individual user controls within a Web Form.
> Each user control can have independent cache durations and implementations of how the caching behavior is to be applied.
> Fragment caching is useful when you need to cache only a subset of a page.
> Navigation bars, header, and footers are good candidates for fragment caching.
23. What is the difference between URL and URI?
A URL (Uniform Resource Locator) is the address of some resource on the Web. A resource is nothing but a page of a site. There are other type of resources than Web pages, but that''s the easiest conceptually.
A URI is a unique identifier to usually a namespace.
Though it looks like a URL but it doesn’t have to necessarily locate any resource on the web.
URI is a generic term. URL is a type of URI.
24. What is the Pre-Compilation feature of ASP.NET 2.0?
Previously, in ASP.NET, the pages and the code used to be compiled dynamically and then cached
so as to make the requests to access the page extremely efficient. In ASP.NET 2.0, the pre-
compilation feature is used with which an entire site is precompiled before it is made available to
users.
There is a pre-defined folder structure for enabling the pre-compilation feature:

* App_Code: stores classes
* App_Themes: stores CSS files, Images, etc.
* App_Data: stores XML files, Text Files, etc.
* App_GlobalResources: stores all the resources at global level E.g. resx files, etc
* App_LocalResources: stores all the resources at local/Page level
25. What are Name Spaces Available in .NET Framework 4:
System
System.Activities Namespaces
System.AddIn Namespaces
System.CodeDom Namespaces
System.Collections Namespaces
System.ComponentModel Namespaces
System.Configuration Namespaces
System.Data Namespaces
System.Deployment Namespaces
System.Device.Location
System.Diagnostics Namespaces
System.DirectoryServices Namespaces
System.Drawing Namespaces
System.Dynamic
System.EnterpriseServices Namespaces
System.Globalization
System.IdentityModel Namespaces
System.IO Namespaces
System.Linq Namespaces
System.Management Namespaces
System.Media
System.Messaging Namespaces
System.Net Namespaces
System.Numerics
System.Printing Namespaces
System.Reflection Namespaces
System.Resources Namespaces
System.Runtime Namespaces
System.Security Namespaces
System.ServiceModel Namespaces
System.ServiceProcess Namespaces
System.Speech Namespaces
System.Text Namespaces
System.Threading Namespaces
System.Timers
System.Transactions Namespaces
System.Web Namespaces
System.Windows Namespaces
System.Workflow Namespaces
System.Xaml Namespaces
System.Xml Namespaces
Accessibility
Microsoft.Aspnet.Snapin
Microsoft.Build Namespaces
Microsoft.CSharp Namespaces
Microsoft.Data.Entity.Build.Tasks
Microsoft.JScript Namespaces
Microsoft.SqlServer.Server
Microsoft.VisualBasic Namespaces
Microsoft.VisualC Namespaces
Microsoft.Win32 Namespaces
Microsoft.Windows.Themes
UIAutomationClientsideProviders
XamlGeneratedNamespace


26. Which DLL translate XML to SQL in IIS?
Sqlisapi.dll

27. Which dll is required to translate XML to SQL in IIS ?
Microsoft.data.sqlxml.dll

28. What is the base class of .NET?
System.Object is the base class of .NET.

29. what is Boxing and Unboxing?
Boxing is an implicit conversion of a value type to the type object
int i = 123; // A value type
Object box = i // Boxing. A temporary box for the box reference will be created on the heap

memory.

Unboxing is an explicit conversion from the type object to a value type
int i = 123; // A value type
Object box = i; // Boxing
int j = (int)box; // Unboxing

30. What is the difference between an EXE and a DLL?
An EXE is portable and executable with a entry point (main function) but dll is not portable and

executable since it has no entry point.
An EXE can consume dll''s.

31. What is strong-typing versus weak-typing? Which is preferred? Why?
Strongly typed is nothing but the method that should support with the equal parameters. Ex:

Delegates

32. Difference between abstract class and interfaces?
Abstract class can have atleast one abstract method whereas in interface each and every

method should be abstract.
Abstract classes are inherited whereas interfaces are implemented by other classes.
for more differences pls check https://www.logicsmeet.com/forum/23488-Difference-Between-

Abstract-Class-and-Interface-in-.NET.aspx


33. How to get distinct values from an array in C#?
[C#]

public int[] GetDistinctValues(int[] arr)
{
List<int> lst = new List<int>();
for (int i = 0; i < arr.Length; i++)
{
if (lst.Contains(arr[i]))
continue;
lst.Add(arr[i]);
}
return lst.ToArray();
}


34. How do you split a string based on a character without using string.split function?
System.Text.RegularExpressions namespace have to be imported to use Regex.Split() method

35. Regular expression for validating the IP Address using Javascript?
[JavaScript]
function isValidIPAddress(ipaddr) {
var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
if (re.test(ipaddr)) {
var parts = ipaddr.split(".");
if (parseInt(parseFloat(parts[0])) == 0) { return false; }
for (var i=0; i<parts.length; i++) {
if (parseInt(parseFloat(parts[i])) > 255) { return false; }
}
return true;
} else {
return false;
}
}


36. Difference between Linked List and Array.
The array''s features all follow from its strategy of allocating the memory for all its elements in

one block of memory. Linked lists use an entirely different strategy.
Linked lists allocate memory for each element separately and only when necessary.

An array allocates memory for all its elements lumped together as one block of memory. In

contrast, a linked list allocates space for each element separately in its own block of
memory called a "linked list element" or "node". The list gets is overall structure by using

pointers to connect all its nodes together like the links in a chain.


37. Write a program to remove dubbles in a string?

[C#]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RemoveDoubles
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please Enter a string to remove Doubles:");
string strInput = Console.ReadLine();
Program obj = new Program();
string strOutput = obj.RemoveDubbles(strInput);
Console.WriteLine(strOutput);
Console.ReadKey();
}

public string RemoveDubbles(string input)
{
string output = string.Empty;
for (int i = 0; i < input.Length; i++)
{
if (i == input.Length - 1)
output = output + input[i];
else if (input[i] != input[i + 1])
{
output += input[i];
}
else
i++;
}
if (input.Length == output.Length)
return output;
else
return RemoveDubbles(output);
}
}
}

38. What are response files in .net?
A response file is a text file that contains a set of compiler commandline switches. When you

execute CSC.exe, the compiler opens response files and uses any switches that are specified in

them as though the switches were passed to CSC.exe on the command line.

39. When you install the .NET Framework, it installs a default global CSC.rsp file in the

%SystemRoot%\Microsoft.NET\Framework\vX.X.Xdirectory (where X.X.X is the version of the

.NET Framework you have installed)


40. Can an object instantiated using const keyword?
No. Only possible constant reference types are string and null.


41. What is the base class of .net?
System.Object

42. Difference between Cookies and Session in ASP.Net

Both session and cookies are used to store user specific information.
If your website has got huge volume users then using session is not recommeded as it eats your

memory. In such cases cookies are the best choice which saves in client machine.

In fact both session and cookie uses cookie but in the case of cookie all information will be

stored in client space but for session only sessionid will be stored in user system.

The main advantage of sesison is you can save datasets, arryas, objects etc in session because

it is saved in server memory. Cookies are normally used when you have to save small and non-

critical data.


43. What base class do all Web Forms inherit from?
System.Web.UI.Page


44. What method do you use to explicitly kill a user’s session?
The Abandon method destroys all the objects stored in a Session object and releases their

resources.
If you do not call the Abandon method explicitly, the server destroys these objects when the

session times out.
Syntax: Session.Abandon


45. How do you turn off cookies for one page in your site?
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.


46. Which two properties are on every validation control?
ControlToValidate & ErrorMessage properties


47. How do you create a permanent cookie?
Setting the Expires property to MinValue means that the Cookie never expires.


48. Which method do you use to redirect the user to another page without performing a round trip to the client?
Server.transfer()


49. Explain what a diffgram is, and a good use for one?
A DiffGram is an XML format that is used to identify current and original versions of data

elements. The DataSet uses the DiffGram format to load and persist its contents, and to

serialize its contents for transport across a network connection. When a DataSet is written as a

DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the

contents, though not the schema, of the DataSet, including column values from both the Original

and Current row versions, row error information, and row order.


50. How to manage pagination in a page?
Using pagination option in DataGrid control. We have to set the number of records for a page,

then it takes care of pagination by itself.


51. What is ADO .NET and what is difference between ADO and ADO.NET?
ADO.NET is stateless mechanism. I can treat the ADO.Net as a separate in-memory database

where in I can use relationships between the tables and select insert and updates to the

database. I can update the actual database as a batch.


52. 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.


53. What is view state?
The web is stateless. But in ASP.NET, the state of a page is maintained in the in the page itself

automatically. How? The values are encrypted and saved in hidden controls. this is done

automatically by the ASP.NET. This can be switched off / on for a single control


54. How many languages .NET is supporting now?
When .NET was introduced it came with several languages. VB.NET, C#, COBOL and Perl, etc. 44
languages are supported.


55. What are different methods of session maintenance in ASP.NET?
Three types of session maintenance:
In-process storage.
Session State Service.
Microsoft SQL Server.


No comments:

Post a Comment