1.) How Garbage collector (GC) works in .NET ?
In .NET,this class method influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the generation, or age category, of memory allocated to an object. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. An application can force garbage collection using the Collect method.
There are following steps in Garbage collection as given below.
The meaning of CONST and READONLY are constant valuses. But there are some difference as given below:-In .NET,this class method influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the generation, or age category, of memory allocated to an object. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. An application can force garbage collection using the Collect method.
There are following steps in Garbage collection as given below.
- The garbage collector searches for managed objects that are referenced in managed code.
- The garbage collector attempts to finalize objects that are not referenced.
- The garbage collector frees objects that are not referenced and reclaims their memory.
2.) Why do we need to call CG.SupressFinalize method ?
Requests that the system not call the finalizer method for the specified object.
public static void SuppressFinalize
(
object obj1
);
Description:-
The method removes obj1 from the set of objects that require finalization. The obj1 parameter is required to be the caller of this method.Objects that implement the interface
can call this method from the IDisposable.Dispose method to prevent the garbage collector from calling Object.Finalize on an object that does not require it.
Requests that the system not call the finalizer method for the specified object.
public static void SuppressFinalize
(
object obj1
);
Description:-
The method removes obj1 from the set of objects that require finalization. The obj1 parameter is required to be the caller of this method.Objects that implement the interface
can call this method from the IDisposable.Dispose method to prevent the garbage collector from calling Object.Finalize on an object that does not require it.
3.) What is the difference between CONST and READONLY?
CONST
1.) A const field can only be initialized at the declaration of the field.
ex. Public int const a =5;
2.)A const field is a compile-time constant.
READONLY
1.) A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used as given below.
readonly int a;
public X()
{
a=1;
}
public X(string s)
{
a=5;
}
public X(string s, int i)
{
a=i;
}
2.) The readonly field can be used for runtime constants, as in the following example:
public static readonly uint A=(uint)DateTime.Now.Ticks;
This can't be possible with const field.
4.) What is COM interop services in .NET? The common language runtime provides two mechanisms for interoperating with unmanaged code: - Platform invoke, which enables managed code to call functions exported from an unmanaged library.
- COM interop services, which enables managed code to interact with COM objects through interfaces.
Yes, you can use the features and functions of Component Services from a .NET Framework components.
6.) You have one base class virtual function how will call that function from derived class ?
Public class A
{
public virtual int m()
{
return 1;
}
}
class B:A
{
public int j()
{
return m();
}
}
7.In which cases you use override and new base ?
To Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier
more details...
8.) What is the output of the below codes ?
try
{
..............
}
catch
{
................ //exception occurred here.
}
finally
{
................
}
OUTPUT-It will throw exception.
9.) What will do to avoid prior case ?
try
{
try
{
.......
}
catch
{
......
//exception occurred here.
}
finally
{
.....
}
}
catch
{
.....
}
finally
{
......
}
try
{
......
}
catch
{
......
}
finally
{
......
}
more details...
10.) Will it go to finally block if there is no exception occurred ?
Yes. The finally block is useful for cleaning up any resources allocated in the try block. Control is always passed to the finally block regardless of how the try block exits.
11.) Will it go to finally block if there is no exception occurred ?
Goto statement are full supported in C#.In Java goto is a reserved keyword that provides absolutely no functionality.
12.) What is different about switch statements in C# ?
10.) Will it go to finally block if there is no exception occurred ?
Yes. The finally block is useful for cleaning up any resources allocated in the try block. Control is always passed to the finally block regardless of how the try block exits.
11.) Will it go to finally block if there is no exception occurred ?
Goto statement are full supported in C#.In Java goto is a reserved keyword that provides absolutely no functionality.
12.) What is different about switch statements in C# ?
No fall-throughs allowed. Unlike the C++ switch statement, C# does not support an explicit fall through from one case label to another. If you want, you can use goto a switch-case, or goto default.
case 1:
cost += 5;
break;
case 2:
cost += 5;
goto case 1;
Learn More Interview Questions and Answers
0 comments:
Post a Comment