21 August 2012

C#.net Interview Question with Anwers

What is use of System.Environment?
Retrieve Information about from Operating System.
How many Comments in C#.net?
S.No Comment Symbol Comment Descr
1     //          Single-Line Comment
2     /* */          Muliti-Line Comment
3     ///             XML Doc Comment.
Can we put multiple catch blocks in a single try statement in C#?
Yes. Multiple catch blocks may be put in a try block.
What are the different types of assemblies - name them?
1)Private2)Public/Shared3)Satellite assembly.
How many types of JIT compilers are available?
1)standard JIT compiler.2)EconoJIT compiler.
How to declare an array for int?    
int[] n;
int -- Data Type
[] -- Name of the Array
n -- name
what are the Non-UI Controls into Component tray in C#.net?
What is mean by "Extractor Method" in C#.net?How do i get?
Extractor Method:
you can create a new method by extracting a selection of code from inside the code block of an existing member. The new method is created containing the selected code, and the selected code in the existing member is replaced with a call to the new method.
Select a Code >>Right Click >>select "Refactor">> Select "Extractor Method" >>create method name in the Screen and Click Ok.
What are the Methods and Property of Thread?
Methods :Invoke(),BeginInvoke(),EndInvoke(),CreateGraphics()
Note:These are Thread-Safe.
Define Interfaces
properties and methods of classes, but unlike classes, do not provide implementations. The Interface statement allows you to declare interfaces, while the Implements statement lets you write code that puts the items described in the interface into practice.
Define User Controls Class?
User Controls are created by the user and are based on the class UserControl (System.Windows.Forms.UserControl). User controls too have properties, methods and events.
What is the top .NET class that everything is derived from?
what are the Access specifiers in C#?
Public, Private, Protected, internal, protected internal.
How to assign a value to a readonly variable in C#?
using constructor
Can you store multiple data types in System.Array?
can we put the Break statement in Finally block?
Does C# Support Static Indexer?
No , It supports instance indexer.
Difference between convert.Tostring() and .Tostring()?
Convert.Tostring() : Support Null Value.
.ToString(): Not support null value.
How do you create empty strings in C#?
Using string.empty
String EString = String.Empty;
Are structs value types or reference types?
it is a value Type.
What do you mean by casting a data type?
Converting a variable of one data type to another data type is called casting. This is also called as data type conversion.
How can you sort the elements of the array in descending Order?
By calling Sort() and then Reverse() methods.
How do you inherit from a class in C#?
Place a colon and then the name of the base class.
What is Anchoring a control and Docking a control?
Anchoring: used to resize controls dynamically with the form.
Docking: to adhere to the edges of its container.
Differentiate between instance data and class data?
Class data in terms of static class is the data that particular class holds in its structure.
Instances can refer to different objects of the same class that hold different values using the same class structure in memory heap.
what is bitarray?
Collection of Bit values.
Is there an alternative of exit() for quitting a C# .NET application?
System.Environment.Exit(int exitCode)/Application.Exit()
What does the term immutable mean?
Data value may not be changed.
What is the difference between the Array.Clone() and Array.CopyTo() ?
Array.Clone -- method returns a new array object containing all the elements in the original array.
Array.CopyTo -- method copies the elements into another existing array.
difference between IS and AS Operator?
IS: Expression evaluates True.Expression is not null.Expression can be cast to type.
as: cast except that it yields null on conversion failure instead of raising an exception.
If casting fails what type of exception is thrown?
Difference between throw and throw ex?
Throw : Original error stack information.
Throw ex: stack error of the exception will be replaced with a stack trace starting at the re-throw point.
Difference between Out and Ref ?
Out :Only for Output Parameter.
Ref: Both In/Output Parameter.
Can you call a WIN32 API function from c# Program?
How do you call a Member method and pass a value Type by reference?
use the "ref" keyword when declaring a Parameter of the Method
public bool GetValue(ref int returnvalue);
How do you declare a Numeric type to String?
Call System.Object.Tostring()
For Example
int idx =0;
string str - idx.ToString();
Does C# support friend class?
what is Purpose of using Return Statement?
returns flow of control from a method to the caller,optionally,passing by a return value.
what is Purpose of using Continue Statement?
It will pass a flow of Control immediately to start of a loop
what is Purpose of using Break Statement?
Exists from the Loop of a FOR,WHILE or DO WHILE Statement
How to use Pascal and camel case in a Program?
Pascal Casing :First Character of all words are upper case and other characters are lower case.
Camel Casing: First charater of all words,except the first word are upper case and Other characters are lower case.
Pascal Casing :Class Name and Method Name
Camel Casing: Variables and Method Parameter .
Which object allows for faster reading of data the Datareader or Dataset?
how to get Default value in C#.net?
use Default Keyword.
Can you override private virtual methods?
What does the keyword virtual mean in the method definition?
What is use of C# "Default" Keyword?
Initialize default value for its type
What is the difference between an EXE and a DLL?
Dll is an In-Process Component whereas EXE is an Out-process Component.
What is the Type of errors?
1)Configuration Errors2)Parser Errors3)Compilation Errors4)Run-Time Errors.
what is a thread?
basic unit to which the operating system allocates processor time.
What the way to stop a long running thread ?
How can you reference currentThread of the Method?
what are the Different level of ThreadPriority?
1) ThreadPriority.Highest2) ThreadPriority.AboveNormal3) ThreadPriority.Normal4) ThreadPriority.BelowNormal5) ThreadPriority.Lowest.
how would you remove the blank entry from array in C#.Net?
Use "StringSplitOptions.RemoveEmptyEntries" in the Array string
like this:
String[] tolist = test.Split(new []{',', ' ', ';'}, StringSplitOptions.RemoveEmptyEntries);
what is the use of Reflection?
Reflection is used to Get assembly metadata using code.
Difference between constant and readonly in C#.net
Constant : Modify a declaration of a fields or Local variable.
Readonly: Modify that you can on field.
what is use of Trim() function and explain different variation ?
Trim function:
remove off Space character from the Beginning and from Ending of the instance.
different Variation in the Trim function:
1)Trim() 2)TrimStart() 3)TrimEnd()
1) Trim():Simply says, remove off spacing from the Start and End of the Instance or string.
2) TrimStart():Simply says, Remove off spacing from the Start of the Instance or String.
2) TrimEnd():Simply says, Remove off spacing from the End of the Instance or String .
what is mean by Trace Class?
Trace class builds both Debug and release.
Whats the use of "throw" keyword in C#?
The throw keyword is used to throw an exception programatically in C#.
Is it Possible to declare an array variable without initialization?
Yes. It is possible .Use "New" keyword.
int[] myArray;
myArray = new int[] {1,3,5,7,9};
Difference between Boxing and unboxing?
Boxing: Convert value type to reference type.
UnBoxing:Convert Reference type to value Type.
which is a basis for event?
Delegates are basis of events.
what are different types of Delegates?
1. Single cast delegate 2. Multicast delegate.
Explain Types of Data Source in .net?
DataSource: Allow data binding on Win Form Controls.
Types of DataSource:
1) Database 2) Service3) Object.
Database :Lets you connect to a database and choose the database objects for your application. This option creates a dataset.
Service:Opens the Add Service Reference dialog box that lets you create a connection to a service that returns the data for your application.
Object:Lets you choose an object that can later be used to generate data-bound controls.

No comments: