- What is static constructor?
- What is the use of Monitor in C#?
- What is lock statement in C#?
- Is overriding of a function possible in the same class?
- How to loop through all rows of the DataTable?
- What is an Array?
- What is an ArrayList?
- What is BitArray?
- What is HashTable?
- What is Queue?
- What is Stack?
- What is SortedList?
- What is Delegates?
- What is a collection?
- What is reflection?
- How is the DLL Hell problem solved in .NET?
- Are private class-level variables inherited?
- What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
- How can you sort the elements of the array in descending order?
- What class is underneath the SortedList class?
- Can you prevent your class from being inherited by another class?
- Can you allow a class to be inherited, but prevent the method from being over-ridden?
- What are the different ways a method can be overloaded?
- What is the use of CommandBehavior.CloseConnection?
- How to declare a property in a class?
- How to declare a property in an Interface?
- How to declare methods into an Interface
- How to load assembly from GAC?
- Difference Between dispose and finalize method?
- What does the term immutable mean?
- What’s the difference between System.String and System.Text.StringBuilder classes?
- Are private class-level variables inherited?
- What class is underneath the SortedList class?
- What happens if you inherit multiple interfaces and they have conflicting method names?
- Types of Errors ?
- Difference between classes and structures?
- How to convert a sentence into Title Case (Capitalize first character of every word)?
- How to sort an array into descending order?
- How to read entire stream contents?
- Write a single line of code to read the entire content of the text file.
- Write a single line of code to create a text file and write contents into it.
- What is the best way to add items from an Array into ArrayList?
- You pass a value-type variable into a procedure as an argument. The procedure changes the variable; however, when the procedure returns, the variable has not changed. What happened? (Choose one.)
- Which of the following is NOT Value type variable?
- You need to create a simple class or structure that contains only value types. You must create the class or structure so that it runs as efficiently as possible. You must be able to pass the class or structure to a procedure without concern that the procedure will modify it. Which of the following should you create?
- What is the correct order for Catch clauses when handling different exception types?
- Why should you close and dispose of resources in a Finally block instead of a Catch block?
- When should you use the StringBuilder class instead of the String class?
- Which of the following statements are false?
- Which of the following are not examples of built-in generic types?
- You are creating a generic class, and you need to dispose of the generic objects. How can you do this?
- Why should boxing be avoided?
- Structures inherit ToString from System.Object. Why would someone override that method within a structure?
- If there is no valid conversion between two types, what should you do when implementing the IConvertible interface?
- With strict conversions enabled, which of the following would allow an implicit conversion?
- Which are NOT acceptable ways to open a file for writing?
- Which of the following are types of changes that can be detected by the File-SystemWatcher?
- Which methods of the FileStream class doesn't affect the Position property?
- How do you not force changes in a StreamWriter to be sent to the stream it is writing to?
- Which of the following create a FileStream for writing when you want to open an existing file or create a new one if it doesn’t exist?
- What types of data can a GZipStream compress?
- What methods can not be used to create a new isolatedStorageFile object?
- An IsolatedStorageFileStream object can be used like any other FileStream object?
- Is String is Value Type or Reference Type in C#?
- What is Attribute Programming? What are attributes? Where are they used?
- What is the difference between Data Reader & Dataset?
- If I want to build a shared assembly, does that require the overhead of signing and managing key pairs?
- What is an application domain?
- What is garbage collection?
- Which namespace is required to use Generic List?
- What is top-level class?
- What is nested class?
- What is partial class?
- What is extension method in C#?
- Which type is inherited by Structs by default?
- Which type is inherited by Class by default?
- What is the default modifier for class in C#?
- By default which class is inherited by a class in C#?
- What is the default modifier for the class member?
- What is the use of var keyword in C#?
- What is anonymous type in C#?
- What is extension method in C#?
- Constructor and Destructor
- Differrence between Array.CopyTo() and Array.Clone()
- what is Static?
- Class A
{
static byte a;
static short b;
static char c;
static int d;
static long e;
static string s;
Public Static Void Main(String args[])
{
Console.WriteLine(a+b+c+d+e+s);
}
} - What’s the advantage of using System.Text.StringBuilder over System.String?
- When do you absolutely have to declare a class as abstract?
- What’s a delegate?
- What’s a multicast delegate?
- What does assert() method do?
- What is a satellite assembly?
- can we declare a block as static in c#?
- How and why to use Using statement in C#?
- What is the name of C# compiler?
- What is object pooling?
- How to create a strong name?
- What is Global Assembly Cache?
- What is Partial Class?
- What is operators in C# and how many types of operators are there in c#?
- What is operator overloading in C#?
- What are Sealed Classes in C#?
- What are the access-specifiers available in c#?
- How to explicitly implement the interface method?
- How to declare a method in an Interface?
- How to write a method in a class and build as .dll
- How do I call a member method and pass a primitive type (Value Type) by
reference? - What is UDP and how does it work?
- How can I programmatically list available queues?
- Which is the Best one for using String concatenation?
- Difference between Static and ReadOnly?
- Which of the following is Mutable?
- HashTable Class is present inside which of the following NameSpace?
- In C# int Refer to?
- What is Microsoft Intermediate Language (MSIL)?
- What will be the output for the following:
String str1="Hello";
String str2=str1;
str1=str1+"C#";
Console.WriteLine(str2); - Difference Between String and StringBuilder
- Which of the following class does not belong to Collection namespace ?
- What debugging tools come with the .NET Framework SDK?
- What are three test cases you should do while unit testing?
- A try block having 4 catch block will fire all catch block or not?
- In this Sample Code which catch block will be executed?
try
{
int j=10;
try
{
int i=10;
j=j-i;
j=i/j;
}
catch(Exception ex)
{
throw ex;
}
}
catch(Exception ex)
{
throw ex;
} - Which keyword is used to prevent one class from being inherited by another class in C#
- Can you store multiple datatypes in an Array?
- An array is fixed length type that can store group of objects.
- What Will be the output of the following Code?
int i = 1;
int j = 1;
i = i++;
j = ++j;
Response.Write(i.ToString() + ":" + j.ToString()); - Which namespace is used to work with RegularExpression in C#?
- Can we throw exception from catch block ?
- How to Find Number of Days for provided date range?
- You have to make user to enter just integer values with TextBox. Can you do this with CompareValidator?
- How can you cache Multiple Versions of a Page?
- Is it possible to notify application when item is removed from cache ?
- Can we declare an array variable with var keyword in C# 3.0?
- Give Some Examples of Generic Classes?
- A Queue is a collection where elements are processed in
- Stack is collection where elements are processed in
- The Items that is put in the Queue is Reads ?
- Which method is used to add an Item to the end of the Queue?
- Whcih method is used to add an Item on stack?
- Which method is used to reads and removes an item from the head of the Queue.
- Which method is used to return an item from the Top of the Stack?
- Can we define generics for any class?
- What is the difference between Parse and TryParse method?
- What is the difference between a.Equals(b) and a == b?
- What is optional and named parameter in C#4.0?
- Can you have different access modifiers on the get/set methods of a property in C#?
- What is obsolete method?
- What first action compiler will take on detection of iterator ?
- With yield break statement, control gets …
- Restrictions of yield in try-catch.
- What are anonymous methods?
- What will happen if you declare a variable named "checked" with any data type?
- What is dynamic keyword ?
- What is difference between var and Dynamic ?
- What is the use of unsafe keyword in C#?
- How can you make your machine shutdown from your program?
- int? d = 1; Type testType = d.GetType(); will result…
- I need to restrict a class by creating only one object throughout the application. How can I achieve this?
- How do we retrieve day, month and year from the datetime value in C#?
- What will be the length of string type variable which is just declared but not assigned any value?
- C# delegate keyword is derived form which namespace?
- What is the use of GetInvocationList() in C# delegates?
- What are the different C# preprocessor directives?
- Which keyword in C# is used to temporarily fix a variable so that its address may be found?
- What is the use of stackalloc keyword in C#?
- Which operators in C# provides automatic detection of arithmetic overflow and underflow conditions?
- What is the CIL representation of implicit and explicit keywords in C#?
- What is the use of ?? operator in C#?
- What are the different Iteration Constructs in C#?
- What are the different method parameter modifiers in C#?
- What do you mean by properties in C#?
- Which class defines different events for controls in C#?
- What is the use of param keyword in C#?
- Which enumeration defines different PenCap in C#?
- When TimerCallback delegate is used?
- What are the different compiler generated methods when a .NET delegate is compiled?
- I would like to check a variable as assigned or not. How can we do that?
- what is the syntax of a nullable variable?
- How can you check a nullable variable is assigned?
- Tell me one reason for dotnet doesn't have multiple inheritance
- I would like to find all the directories of a folder How should I achieve this?
- What is CharEnumerator in C#?
- Why 'static' keyword is used before Main()?
- If i will write a piece of code in finaly block, will it execute if there is an exception in try block.
- Which methods are used to execute javascript code from code behind file?
- What is the main difference between RegisterStartUpScript and RegisterClientScriptBlock?
- What is the page size in SQL Server?
- Can we use Page.PreviousPage to get the value of controls of the previous page in case of response.Redirect ?
- How we can gt the values of control on the previous page in case od server.transfer method?
- what is the class used for dealing with graphics objects
- Write a way to read an image from a path to a bitmap object
- Name any two "Permission Classes" generally used while working with CAS ?
- Does Abstract classes contain Constructor?
- Can we inherit a private class into the public class?
- Can we declare a class as Protected?
- What is the difference between IQueryable<T> and IEnumerable<T> interface?
- Some facts about Virtual methods.
- Explain About ref and out parameters?
- String is a Class then why can't you create a object for the string like this String str = new String();
- Why C# is called Strongly Typed Language?
- Example for Compile time Polymorphism and Example for Run time Polymorphism?
- What is Closed constructed type and Open constructed type?
- What are Generics?
- Write the syntax of foreach loop with hashtable and get the key, value pair from the hashtable?
- When inheriting from a base class, whether the derived class inherits the destructor and constructor from the base class?
- What are the Integer Type Supported by c#?
- Explain the states of a window service application?
- Explain what are the types of window services?
- What is MultiCast Delegate ?
- What for using System.Logging namespace is used ?
- When to use Public and Private access modifiers
- Define different Access modifiers in C#
- When does GarbageCollector runs ?
- What is properties? What are the different types of properties?
- Write an equivalent of exit() for quitting a C# .NET application?
- Where the global assembly cache located on the system?
- Where the shared assemblies stored?
- What’s the C# syntax to catch any possible exception?
- What are the advantages of using Properties in C#.Net?
- What do you mean by static property? Give an example?
- What do you mean by virtual property? Give an example?
- Explain about abstract property. Give an example?
- Is it possible to instantiate a struct without using a new operator and can a struct inherit from another struct or class in C#?
- Can a struct inherit from an interface and what's the type of struct in C#?
- What is the base type from which all structs inherit directly?
- Mention two cases where static constructors can be used?
- Can a class have static constructor?
- How you create partial methods?
- Can you inherit different parts of a partial class from different interfaces and is it possible to create partial delegates and enumerations?
- Show how you specify nested classes as partial classes with example?
- Can a nested class access the outer class? Give an example?
- What is the difference between method parameters and method arguments? Give an example?
- Can you pass value types by reference to a method?
- What is the difference between a constant and a static readonly field?
- Write the different components of LINQ (Language Integrated Query) and state the purpose of LINQ Providers in LINQ?
- How can you implement Standard Query Operators in LINQ?
- What is the use of Standard Query Operators in LINQ?
- What is Regular Expressions in C#.NET?
- What is Zero-Width Assertions in C#?
- What is Finalizer?
- How to install and uninstall Windows Services ?
- What are circular references? Explain how garbage collection deals with circular references?
- How to add controls dynamically to the form using C#.NET?
- Explain what is Extender provider component? How to use this in the project?
- What is the difference between Debug.Write and Trace.Write?
- What is the use of virtual, sealed, override, and abstract?
- What is Primary Interop Assembly (PIA)?
- What is the use of static members in C#.NET?
- What is implementation inheritance and interface inheritance?
- What is C#.NET Generics?
- What is structs?
- What is enum?
- What is the difference between object pooling and connection pooling?
- Difference between static variable and constant in c#?
- Why we are using System.Environment class?
- What is virtual function?
- What is ILDASM?
- What is Satellite Assembly ?
- Which one of the following language is not included in the installation of .net Framework ? (Default Installation)
- Can we have 2 applications run on a same machine using different Framework Versions ?
- Which Object contains all the properties and methods for every Asp.net page ?
- What is Process Identifier?
- Which of these classes allow us to add a printer dynamically?
- How many types of comments are there in C#?
- Can we specify the access modifiers for the get and set accessors in a property?
- class Program
{
static void Main(string[] args)
{
Console.WriteLine(clsNewStatic.count);
clsNewStatic.count = 20;
Console.WriteLine(clsNewStatic.count);
clsNewStatic t = new clsNewStatic();
Console.WriteLine(clsNewStatic.count);
}
}
public class clsNewStatic
{
public static int count = 10;
} - What is the output of this code segment ?
using System;
class A
{
A()
{
Console.WriteLine("Class A");
}
}
class B:A
{
B()
{
Console.WriteLine("Class B");
}
static void Main()
{
B obj=new B();
}
}
The options are:
1) Class A
Class B
2) Class B
Class A
3)None of these
4) error message - Difference between | and ||
- What is the difference between == and Equals?
- Difference between Type.GetType() and Object.GetType()
- What is the preferred model for event handling in C#?
- Which of these variables are compiled as an anonymous type?
- What is Asynchronous call and how it can be implemented using delegates?
- What is ' ?? ' operator ?
- Which is the correct declaration of the Main() method
A) static long Main()
{
return 300;
}
B) static int Main()
{
return;
}
C) static void Main()
{
return;
} - How can we underline a particular character in the Text of the Window Label
- How can we make our C# classes to interoperate with other .net languages ?
- Can C# support variable argument on method ?
- Consider
List<string> s=new List<string>();
s.Add("one");
List<string> p=new List<string>();
p.Add("one");
What should be written in the braces?
if (s==p)
{
} - How is anchoring different from docking?
- How can we disable the context menu for a textbox control?
- How to turn off autolisting feature in the code window of C# applications?
- What is the difference between WindowsDefaultLocation and WindowsDefaultBounds?
- Difference between String and string in c#?
- Difference between String and String Buffer in c#?
- Differences between Show and ShowDialog methods?
- Can we have statid indexers in C#?
- What is Nullable types in c#?
- Can we pass default parameter values in C#?
- How can we prevent the conflicts in methods with same names, signatures belonging to multiple interfaces when these interfaces are implemented?
- For which type of arrays, we can use the params keyword?
- What is the use of yield keyword in C#?
- Does the finally block execute even when we have unhandled exceptions?
- Can you allow a class to be inherited, but prevent the method from being overridden?
- Why the Main() method is static?
- Can DateTime be assigned null ?
- Can we overload static constructors?
- What is the name used to describe the sending of groups of events captured on the client to the server?
- A visitor is buying groceries on an online shopping web site.
Which of the following pieces of information do you think are suitable for storage as session state?
Options:
1. The timeout period for the session
2. The visitor's registration details
3. The visitor's shopping basket
4. The web site's help desk phone number
5. The visitor's name
6. The visitor's page display preferences - Which of the following are forms of state information?
a. Application state
b. Server state
c. Session state - Can we use goto statement in the finally block?
- using System;
class aa
{
}
class bb : aa
{
}
class cc : bb
{
}
Can you create an instance of class aa from
the instance of class cc? - How can we create an array with non-default value in C#?
- Which of these methods can be put in Thread class constructor?
a))void abc()
{
}
b)int demo()
{
return 100;
}
c)void mymethod(int a)
{
} - What is Value Types versus Reference Types?
- Difference between var and dynamic?
- why can you prove that string is immutable datatype while StringBuilder is Mutable Datatype ?
- An instance of which of the following must be created to read files across a network?
- In what format does C# expect data to be streamed?
1. Simple binary
2. SOAP
3. Unserialized - How can you rename a file in C#?
- Can we change the dimensions of the array like arr[4,5] dynamically ?
- How many catch Statement can be associated with single try statement?
- Difference between typeof and Type.GetType
- Will this code compile?
try
{
}
catch
{
string s="error";
throw s;
} - What will be the output of ths code?
try
{
try
{
throw new NullReferenceException();
}
catch (Exception ex)
{
throw new FormatException("error", ex);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.GetType().ToString());
} - Why Object Pool is required?
- What is the correct syntax of region directive?
a)#region
#end region
b) #region
#endregion
c)region
endregion - What will be the output of this code?
const int a = int.MaxValue;
const int b = int.MaxValue;
int r;
checked
{
r = a * b;
Console.WriteLine(r);
} - Which of these statements will allow us to determine if Ctrl(Control) key was
pressed? (e is a variable of KeyEventArgs class) - Which of these allows you to catch non-CLS compliant Exceptions?
1) catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
2) catch
{
throw;
}
3) catch(IOException ex)
{
Console.WriteLine(ex.Message);
} - What is the escape sequence of null character?
- What will be the output of this command?
string s="yes";
while (s=="yes")
{
for(int i=1;i<=5;i++)
{
Console.WriteLine("hello");
}
} - What will be the output of this code?
for (int i = 1; i <= 3; i++)
{
for (int j = i; j <= 3; j++)
{
Console.Write(j + "");
}
Console.WriteLine();
}
1) 1
12
123
2) 1
21
321
3)123
23
3
4)None of these - What is the use of default keyword?
- Can we call a function from derived class if you have one base class Virtual Function ?
- What is an INDEXER in c# ?
- How can we sort elements in an array in descending order ?
- Is there any Supplement of exit() method or quitting a C# application ?
- How to restrict a class not to be inherited.?
- Can we use the Throws clause to raise an exception ?
- What are the different Name Spaces that are used to create a localized application ?
- What are the different Debugging tools come with .Net SDK ?
- What does the assert() method do in debug compilation ?
- Can we force Garbage Collector to run ?
- Why is it not a good programming practice to use empty Destructors ?
- Explain two different scenarios where the Static Constructors can be used ?
- Write the difference between Stack and Heap?
- What is the difference between "Convert" class and "Parse()" method?
- Write the difference between Group box control and Panel control?
- Will the Following code compile ?
double d = 5689.56;
int i = d; - What will be the output of the following code ?
using System;
public class BaseClass
{
public BaseClass()
{
Console.WriteLine("You are in Base Class of DotNetFunda");
}
}
public class ChildClass : BaseClass
{
public ChildClass()
{
Console.WriteLine("You are in Child Class of DotNetFunda");
}
static void Main()
{
ChildClass CC = new ChildClass();
}
} - Which of the following is a value type in C# ?
- Difference between Value types and Reference types ?
- Can we have Secured a secured web page using HTTP protocol instead of HTTPS ?
- What is Call By Out parameter?
- What are Object Initializers?
- What is Window Service? What are the three types of programs required to operate a
service? - What is Type Inferencing?
- Is it possible to get the Registry values through C#.net , if so what classes used for it?
- What is Jump Constructs?
- Can you declare the override method as static while the original method is non-static ?
- Why is the "new" keyword used for instantiating an object in .Net ?
- What is the purpose of x86, x64 and anycpu platform switch in C# compiler?
- How to sort array elements in descending order in C#?
- What are Declaration Statements ?
- What is Scavenging in .NET?
- How can we clear Cache stored in browser ?
- List<int> list = new List<int>();
list.Add(44);
list.Add("mystring");
console.writeline(list);
console.writeline(list);
C# Interview Questions
List of C# Interview Questions. To get the answers of these C# Interview Questions, click here.
