Breaking News

Editors Picks

Sunday, August 8, 2010

C# interview Question And Answer

C# interview Question-and answer


1) What’s the advantage of using System.Text.StringBuilder over System.String?
Strings are object which cannot be modified once created. Each time when the string is operated an instance for the object is created. String builder is more efficient then the system.string while manipulating on string.

2) Can you store multiple data in System.Array?
Using System.Array to store multiple data types is not possible. In case if the user is willing to store in multiple data types they can make use of array list.

3) What’s a delegate?
A delegate is a type-safe object which can point to another method or multiple methods in the application.
A delegate consist of
Method name
Argument (if any)
Return value (if any)

4) What is hashtable?
Hashtable is a .NET datatype that helps in retrieval of data using a unique key.

5) Can multiple catch blocks be executed?
It is not possible to execute multiple catch block. Since once the catch code fires the controlled is automatically pass to the final code and the final code starts execution.

6) What are advantages of Microsoft-provided data provider classes in ADO.NET?
It is able to handle single tier to multi-tier.
Provides data security.
They perform task faster.

7) What is an interface class?
Interface class specify the methods, properties and events but they don’t provide implementation as like classes. The implementation is done by the class and are defined as separate entity from classes.

8) Can you inherit multiple interfaces?
Multiple interface cannot be implemented using .NET. since .NET doesn’t support interface.

9) What is an abstract class?
Abstract class is a class that cannot be instantiated. It is a class to be inherited and the methods to be overridden.

10) What’s a multicast delegate?
A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.

11) What does the term immutable mean?
Immutable refers to data values which cannot be changed.

12) What is difference between of the C and C#?
C is not case sensitive but C# is sensitive.
C# focus more on design and C is on function.
C# is object oriented and C is structured language.
C# is type safe but C is not.

13) What is the difference between C# and java?
Java is cross platform language and C# is window specific language.
C# relies on windows system foundation whereas java rely on java virtual machine.
JVM converts byte code into executable code. C# converts into MSIL.

14) What is the syntax to inherit from a class in C#?
Class newclass: baseclass
Class can be inherited by placing the class name after the colon.

15) What is Microsoft.Access?
Microsoft.Access is used to connect to database inorder to access them.

16) How to Do File Exception Handling in C#?
Exception handling is a built in mechanism in .NET framework. It enables to identify errors and to handle run time errors. They contain lot of standard exception.

17) What’s the difference between // comments, /* */ comments and /// comments?
// comment is used to said single comment.
/* */ Comment is used for multiple line comment.
/// comment is for XML documentation comment.

18) How can you sort the elements of the array in descending order?
Sorting the elements in the descending order can be done by the function sort() and the reverse() method.

19) How’s the DLL Hell problem solved in .NET?
Assembly versioning specify the library that required by the application to run and also the version of the library to the application.

20) What is the use of serializable keyword in C#?
Declaring a class with the keyword serializable enables the object to be serialized mainly for exchange of data between two system. If the object going to inherit by any other object then serialization downstream required to be used.

21) Pointers in c#?
C# supports pointers but it required to be specified within the unsafe code.
For example
Unsafe
{
// usage of pointers
}

22) How does C# implement events?
C# implements events by the following:-
Pointers
Delegates
DLLs

23) What does assert() do?
Assert taken the parameter in Boolean condition, while debugging it shows the error dialog when the condition fails. If the condition true the program proceeds without any interruption.

23) What is the name of C#.NET compiler?
C#.NET compiler is JIT(Just in time) compiler.

24) What is true about readonly variable in C# code?
Read only file is to be initialized at the time of the construction of the object.

25) What is shadowing?
Shadowing is a VB.NET concept which can implement base class without overriding the members of the class. Any class member can be shadowed by using the keyword SHADOW.

C# interview Question-and answer


1) What is a process and threads?
A process is an entity which has its own memory space and maintain state information.
Thread is an independent execution path, able to run simultaneously with other threads.

2) What is an indexer in C#?
A special kind of operator overloading is indexer(). Once the indexer has been defined the class object can be defined using array syntax.

3) What is the advantage of using generics in C#?
It is not required to test on data types
It performs sorting much better
Generic delegates can also be used in dynamically generated code without requiring the generation of a delegate type.

4) What is the advantage of using delegates in C#?
They are managed function pointers.
They are type checked and held in spaces that can be reclaimed by the memory manager.

5) Code written in C# can not used in which of the languages?
Code written in C# cannot be used in java.

6) what is object pooling?
The great advantage of using .NET is that it helps to write code to pool objects and threads. Object pooling is mainly to share objects between different clients.

7) Explain about 'this' and where and when it should be used?
This keyword is used to refer to the current class instance. It provides support while debugging.

8) What is a pre-requisite for connection pooling?
All the process should accept to share the same connection, parameters and including the settings.

9) Explain ACID rule of thumb for transactions?
All transaction to be automatic, each single unit should be independent, consistent, durable and isolated.

10) What is IL?
IL stands for Intermediate language. C# compiler converts the program into intermediate language.

11) Is it possible to have different access modifiers on the get/set methods of a property?
No, it is not possible to have different access modifier. If the user require to have different modifier then they can create by making the property internal and create internal method separate from property.

12) How to compare two strings in C#?
In general strings can be compared using == and != operators. The following comparison can be done in C# using the following if ((object) str1 == (object) str2) { }.


13) What do you know about .NET assemblies?
Assemblies are smallest unit based on which the development and deployment of .NET application possible. They are also known as the building block of an progam.

14) How do you mark a method absolete?
[Obselete] public int Spy{} {..}

15) How is method overriding different from overloading?
In overriding you change the behavior of a derived class. Overload is to have the same method name within the class.

16) What is boxing?
Encapsulating a copy of a value type in an object is termed as boxing.

17) How does assembly versioning in .NET prevent DLL Hell?
.NET allows assemblies to specify the name AND the version of any assemblies they need to run.

18) What is the difference between const and static read-only?
The major difference is that static variable can be modified by the class which contains it whereas a variable declared const cannot be changed.

19) Explain the three services model commonly know as a three-tier application.
Presentation
Business
Data

20) How do I convert a string to an int in C#?
using System;
class conversion
{
public static void Main()
{
String s1 = "100";
int y = Convert.ToInt32(s1);
Console.WriteLine(y);
}
}

21) Does C# support templates?
No, C# doesn’t support templates. They support a type of template known as generic. It has a similar syntax but instantiated during run time.

22) Why does my Windows application pop up a console window every time I run it?
The properties setting should be in windows application and not console application.

23) Does C# support C type macros?
C# doesn’t support c type macros. Some of the predefined C macros is also defined in macros, but they will be useful in debug time.

24) Can you declare the override method static while the original method is non-static?
Signature of the virtual method remains the same. The virtual keyword alone is changed to override.

25) How can I get the ASCII code for a character in C#?
Casting the char to an int will give you the ASCII value:
char c = 'f';
System.Console.WriteLine((int)c);
If you what to get a char ASCII value which is in a string then the following syntax can be used:
For Example:- S= Programming
System.Console.WriteLine((int)s[3]);//s[3] returns the ACSII value of ‘g’
The base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.


C# interview Question and answer


1. Explain the three services model commonly know as a three-tier application.
The three service model in three tier application are
Data
Business
Presentation


2. what are the rules to be followed while naming variable in C#?
The following are the rules to be followed
It should be unique
It can have any number of character
Shouldn't use keyword as names
It should start with letter or underscore.

3. What are the different types of Data?
C# supports two types of data:-
Value type: - Value type directly contains the data. Once the variable declared the system allocates memory to store value
Reference type: - They don't contain variable rather the reference to the variable.

4. Explain about comment entry?
Comments is also a part of the program that explains about the code. Compilers ignore the comments. comments are enclosed within '/* and */.

5. Explain about protected internal access specifier?
internal access specifier will hide the member function and variables to be accessed by other function and objects, other then the child class. It plays an important role during implementing inheritance.

6. How do you specify a custom attribute for the entire assembly (rather than for a class)?
Global attribute require to appear on top level and before the namespace specification.
For eg:-
using System;
[assembly : MyAttributeClass] class X {}

7. How do you mark a method obsolete?
[Obsolete] public int x1() {...}
Obsolete is the keyword used in front of the method to make it obsolete.

8. What do you know about .NET assemblies?
Assemblies are the smallest units of versioning and deployment in the .NET application. Assemblies are also the building blocks for programs such as Web services, Windows services, serviced components, and .NET remoting applications.

9. What’s the difference between private and shared assembly?
The assembly used inside the application are called as private assembly, they do not require any strong name to be identified.
shared assembly as the name indicates can be used by multiple applications and it is very much essential that it has a strong name.


10. What’s a strong name?
A strong name require to have the following fields:-
assembly,
version number,
culture identity,
public key token.

11. Can you have two files with the same file name in GAC?
Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, 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.

12. How can you create a strong name for a .NET assembly?
Strong Name tool (sn.exe) which can be used to create strong name.

13. What is delay signing?
It allows to place a shared assembly by just placing a public key in the assembly. It is more secure and helps the developers to work with strong name and shared assemblies.

14. Is there an equivalent of exit() for quitting a C# .NET application?
System.Environment.Exit is an equivalent of exit() that enables to quit from the application.

15. How do I make a DLL in C#?
target:library compiler option inorder to make a DLL in C#.

16. Is there regular expression (regex) support available to C# developers?
Yes, regular expression are supported by .NET class. System.Text.RegularExpressions namespace provide the expression for regular expression.

17. What connections does Microsoft SQL Server support?
Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords)

18. What is trace and debug in C#?
.NET allows very useful class that help in monitoring the working of the program. Trace and Debug can be very powerful development tools that can help kill hard to find bugs by making them glaringly obvious.

19. What optimizations does the C# compiler perform when you use the optimize+ compiler option?
optimize branches over branches
unreachable code
getting rid of unused locals.

20. How do I create a multi language, multi file assembly?
Unfortunately, this is currently not supported in the IDE. To do this from the command line, you must compile your projects into netmodules (/target:module on the C# compiler), and then use the command line tool al.exe (alink) to link these netmodules together.


C# interview Question- and answer


1. How do I declare inout arguments in C#?
The equivalent of inout in C# is ref. , as shown in the following
example:
public void My1 (ref String str1, out String str2)
{
...
}
When calling the method, it would be called like this: String s1;
String s2;
s1 = "Hi";
My1(ref s1, out s2);
Console.WriteLine(s1);
Console.WriteLine(s2);
Notice that you need to specify ref when declaring the function and calling it

2. Can you change the value of a variable while debugging a C# application?
Yes, you can change the value of a variable while debugging a C# application.

3. What is the difference between const and static read-only?
static read only can be modified by class that containing whereas const can never be modified.

4. What namespaces are necessary to create a localized application?
System.Globalization, System.Resources

5. How do you inherit from a class in C#?
Place a colon and then the name of the base class.

6. Does C# support parametrized properties?
C# does not support parametrized properties. However it supports the concept of indexer. An indexer is a member which enables the object to be indexed as in array.

7. Does C# support C type macros?
C# doesn't support C type macros. Some of the C macros are found in .NET class but they only work with debug builds.

8. How do I convert a string to an int in C#?
Convert.ToInt32 is the keyword to be used to convert string to int.
For eg:-
class ConvStrtoInt
{
public static void Main()
{
String str = "2345";
int x = Convert.ToInt32(str);
Console.WriteLine(x);
}
}

9. What is the .NET datatype that allows the retrieval of data by a unique key?
HashTable is the datatype to be used to retrieve data by unique key.

10. What is the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

11. How can I get the ASCII code for a character in C#?
Casting the char to an int will give you the ASCII value: char c = 'f'; System.Console.WriteLine((int)c); or for a character in a string: System.Console.WriteLine((int)s[3]); Even the base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.

12. How do I create a Delegate/MulticastDelegate?
C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method's name.
For example,
System.Threading.ThreadStart: Foo MyFoo = new Foo();
ThreadStart del = new ThreadStart(MyFoo.Baz);

13. How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.

14. What are the ways to deploy an assembly?
Some of the ways to deploy assembly are as follows:-
MSI installer
XCOPY
CAB archive

15. Difference between imperative and interrogative code.
There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value.

16. Difference between imperative and interrogative code.
There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value.

17. Explain manifest & metadata?
Manifest is metadata about assemblies. Metadata is machine-readable information about a resource, or “”data about data.” In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.

18. Difference between value and reference type. what are value types and reference types?
Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type - class, delegate, interface, object, string
Reference types are stored in the Heap

19. What are the two kinds of properties.
Two types of properties in .Net: Get and Set

20. What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
Read more ...

Contact Us

Name

Email *

Message *