You are on page 1of 7

http://www.dotnetanalyst.com/FAQs/CSharp.

aspx
What is the difference between Overloading and Shadowing?
Overloading : A Member has the name, but something else in the signature is different.
Shadowing : A member shadows another member if the derived member replaces the base
member
What is the difference between Overloading and Overriding?
Overloading : Method name remains the same with different signatures.
Overriding : Method name and Signatures must be the same.
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
--------------------------------------------------------------------------------
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
what is the difference between array and arraylist?
Arrays are always fixed size in nature and ArrayList can grow dynamically.
what is the difference between readonly and constant varaibles??
readonly - variables are dynamic constant, you can modify the value in the constructor only.
constant - variables are constant, you cannot change the values once its declared as a constant.
What is enum?
An enum type is a distinct type that declares a set of named constants.They are strongly typed
constants. They are unique types that allow to declare symbolic names to integral values.
public enum Grade {
A,
B,
C
}
What is the life cycle for an object?
1. The object is created.
2. Memory is allocated for the object.
3. The constructor is run.
4. The object is now live.
5. if the object is no longer in use, it needs finalization.
6. Finalizers are run.
7. The object is now inaccessible and is available for the garbage collector to carry out clean-
up.
8. The garbage collector frees up associated memory.
What is CodeDOM?
 CodeDOM is an object model, which is used to generate a source code. It is designed to be
language independent - once you create a CodeDom hierarchy for a program we can then
generate the source code in any .NET complaint language.
What is Static class?
1.A static class can only contain static members.
2.We cannot create an instance of a static class.
3.Static class is always sealed and they cannot contain instance constructor
4.Hence we can also say that creating a static class is nearly same as creating a class with
only static members and a private constructor (private constructor prevents the class from
being instantiated).
---Good example is the System.Math class
What are method parameters in C#?
C# is having 4 parameter types which are
1.Value Parameter. default parameter type. Only Input
2.Reference(ref) Parameter. Input\Output
3.Output(out) Parameter.
4.Parameter(params) Arrays
1234
What is the
difference
between out
and ref
parameter?
Difference is that out parameters need to be declared but not initialized.
ref parameter will have a value even before the method call..
what is the Concept of heap and stack?
Local Variables Stack
Free Memory (Larger Memory Area than Stack). Heap
Global Variables Permanent Storage area
Program Instruction
what are value types and reference types?
Value type Reference type
1. Value types are stored in the Stack 1. Reference types are stored in the Heap
2. Eg. bool, byte,char, decimal,double,enum, 2. Eg. class, delegate, interface, object, string
float, int, long, sbyte, short, strut, uint, ulong,
ushort
What are primitive data types?
Primitive data types are basic data types. C# is having 15 primitive data types
Value types - 13
boolean, byte, char, double, decimal, float, int, long, short, sbyte, ushort, uint, ulong
Ref types - 2
string and object
what are the differences between string and stringbuilder?
System.string System.Text.StringBuilder
1.Reference type ie stored in the heap 1.Reference type ie stored in the heap.
2. Immutable, Once the string object is 2. Mutable, Even after object is created, it can
created, its length and content cannot be be able to modify length and content.
modified.
3. Slower 3. Faster
4. Eg // This method will create almost 4. Eg // This will use only one instance and
100000 String instances will allocate the space needed for each
String s = "MyName"; append, efficiently. Much much better..
for( int i=0; i<100000; ++i) StringBuilder sb = new StringBuilder(s);
s+=i.ToString(); for( int i=0; i<100000; ++i)
sb.Append(i.ToString());
what is the difference between Manifest and Metadata?
Manifest Metadata
1. Manifest describes assembly itself 1. Metadata describes contents in an assembly
2. Assembly name, Version number, Culture, 2. classes, interfaces, enums, structs, etc., and
Strong name, list of all files, Type references their containing namespaces, the name of each
and referenced assemblies type, its visibility/scope, its base class, the
interfaces it implemented, its methods and
their scope, and each method’s parameters,
type’s properties, and so on
what is the difference between abstract class and interface?
Abstract Classes Interfaces
Abstract classes are incomplete classes Interfaces are used to define specifications
can have concrete methods cannot have concrete methods
used to achieve polymorphism used to achieve multiple inheritance
members can have access modifiers(public, members access modifiers are public by
abstract, virtual, private, internal) default(can not declare explicitly)
What are the access modifiers in C#
There are Four access modifiers
public : Members are fully accessible
protected : A protected member is accessible from within the class in which it is declared
internal : Internal members are accessible only within files in the same assembly
private : Private members are accessible only within the body of the class
What are the Accessibility levels in C#
There are five Accessibility levels
public : Access is not restricted.
protected : Access is limited to the containing class or types derived from the containing class.
internal : Access is limited to the current assembly. protected internal : Access is limited to the
current assembly or types derived from the containing class.
private : Access is limited to the containing type.
What is Dispose method in .NET?
.NET provides "Finalize" method in which we can clean up our resources. But relying on this
is not always good so the best is to implement "IDisposable" interface and implement the
"Dispose" method where you can put your clean up routines
1234

How to get the Assembly version programatically?


System.Reflection.AssemblyName myAssemblyName =
System.Reflection.AssemblyName.GetAssemblyName(@"D:\SepTest\Bin\Ajax.dll");
MessageBox.Show(myAssemblyName.Version.ToString());
What is delay signing?
Delay signing allows you to place a shared assembly in the GAC by signing the assembly
with just the public key. This allows the assembly to be signed with the private key at a later
stage, when the development process is complete and the component or assembly is ready to
be deployed.
What is partial class?
- The partial classes use the new keyword partial and are defined in the same namespace.
- partial classes as a class definition split across many files for convenience
- Partial classes must use the same access modifier (for example Public Protected and
Private).
- If any single part is abstract (MustInherit), the whole class is abstract.
- If any parts are sealed (NotInheritable), the whole class is sealed.
- If any part declares a base type, the whole class inherits that base type.
- Parts can specify different interfaces, but the whole class implements all interfaces.
- Delegates and enumerations cannot use the partial modifier.
What is Generics in C#?
Parametric Polymorphism is a well-established programming language feature. Generics
offers this feature to C#.
The concept is very close to Templates in C++.
In the generic List<T> collection, in System.Collections.Generic namespace, the same
operation of adding items to the collection looks like this:
// The .NET Framework 2.0 way of creating a list

List<int> list1 = new List<int>();


list1.Add(3); // No boxing, no casting
list1.Add("First item"); // Compile-time error
What is Anonymous method in C#(.NET 2.0)?
Anonymous methods is a new feature in C# 2.0 that lets you define an anonymous (that is,
nameless) method called by a delegate.

For example, the following is a conventional SomeMethod method definition and delegate
invocation:

class SomeClass
{
delegate void SomeDelegate();
public void InvokeMethod()
{
SomeDelegate del = new SomeDelegate(SomeMethod);
del();
}
void SomeMethod()
{
MessageBox.Show("Hello");
}
}
You can define and implement this with an anonymous method:
class SomeClass
{
delegate void SomeDelegate();
public void InvokeMethod()
{
SomeDelegate del = delegate()
{
MessageBox.Show("Hello");
};
del();
}
}

The anonymous method is defined in-line and not as a member method of any class.
Additionally, there is no way to apply method attributes to an anonymous method, nor can
the anonymous method define generic types or add generic constraints.

Anonymous methods can be used anywhere that a delegate type is expected. You can pass
an anonymous method into any method that accepts the appropriate delegate type as a
parameter:
what are the different levels Thread priority provided by .NET?
- ThreadPriority.Highest
- ThreadPriority.AboveNormal
- ThreadPriority.Normal
- ThreadPriority.BelowNormal
- ThreadPriority.Lowest
We can change the thread priority setting by
Threadname.Priority=ThreadPriority.Highest
What is event bubbling?
Server Controls like datagrid, Datalist, Repeater can have child controls inside them.For
example Combo box inside datagrid. The Child controls(combo box) send their events to
parent(datagrid) is known as event bubbling.
what are the serialization types supported in .NET?
Serialization is the process of saving the state of an object by converting it to a stream of
bytes. The object can then be persisted to file, database, or even memory. The reverse process
of serialization is known as deserialization.
The serialization types are as follows
1. XML serialization
2. Binary serialization
3. Soap serialization.
Code snippet for XML serialization
System.Xml.Serialization.XmlSerializer xs = new
System.Xml.Serialization.XmlSerializer(typeof(Employee));
FileStream OutputFS = new FileStream(@"C:\output.xml",FileMode.Create);
xs.Serialize(OutputFS, emp);
Code snippet for Binary serialization
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
FileStream OutputFS = new FileStream(@"C:\output.bin", FileMode.Create);
bf.Serialize(OutputFS, emp);
Code snippet for Soap serialization
System.Runtime.Serialization.Formatters.Soap.SoapFormatter sf = new
System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
FileStream OutputFS = new FileStream(@"C:\output.soap", FileMode.Create);
sf.Serialize(OutputFS, emp);

What is Array?
Example of Single Dimension Array in .Net
int [] intArray = new int[3];
intArray[2] = 22; // set the third element to 22

Example of Multi Dimension Array in .Net


int [][] myTable = new int[2,3];
myTable[1,2] = 22;

Example of Jagged Array in .Net : Variable Length Array in .Net


int [][] myTable = new int[3][];
myTable[0] = new int[5];
myTable[1] = new int[2];
myTable[2] = new int[4];
myTable[0][2] = 11;

Example of String Array in .Net


string []names = new string[4];
names[2] = “God will make me win”;

Limitation of Arrays
-->The size of an array is always fixed and must be defined at the time of instantiation of an
array.
-->Secondly, an array can only contain objects of the same data type, which we need to define
at the time of its instantiation.
What is Nullable Type in .Net 2.0?
Nullable in .Net 2.0, helps to determine whether variable has been assigned a value or not.
Example: Quiz application having option yes/no, but it should displayed “Not Attempted”
when user does not make any choice.
Syntax :
Nullable b = null
//only for C#
bool? b = null;

Example :
if (b.HasValue)
Console.WriteLine("User has Attempted Given Question");
else
Console.WriteLine("User has not Attempted Given Question");
1234

What is CLR??
The CLR(Common Language Runtime) Responsibilities are
√ Garbage Collection
√ Code Access Security
√ Code Verification
√ IL( Intermediate language )-to-native translators and optimizer’s
What is CAS?
.NET has two kinds of security:
--Role Based Security
--Code Access Security
======================

CAS is the CLR's security system that enforces security policies by preventing unauthorized
access to protected resources and operations. Using the Code Access Security, you can do the
following:
-Restrict what your code can do
-Restrict which code can call your code

Code access security consists of the following elements:


permissions - FileIOPermission (when working with files), UIPermission (permission to use
a user interface), SecurityPermission (this is needed to execute the code.
permission sets - FullTrust, LocalIntranet, Internet, Execution and Nothing are some of the
built in permission sets in .NET Framework
code groups - My_Computer_Zone, LocalIntranet_Zone, Internet_Zone
policy - There are four policy levels - Enterprise, Machine, User and Application Domain
We can acheieve CAS in two ways :
from the .NET Configuration Tool or from the command prompt using caspol.exe. First we'll
do this using the .NET Configuration Tool. Go to Control Panel --> Administrative Tools -->
Microsoft .NET Framework Configuration
1234

You might also like