Need answeres for these interview questions...

Posted by Gayathri under ASP.NET on 6/14/2012 | Points: 10 | Views : 1176 | Status : [Member] | Replies : 3
1)Why do we need Garbage collector in .net?
When we close the object like this - obj.close();
why do we still need garbage collector?

2) what is the difference between sqlcon.close()
sqlcon.dispose();

3) why is the syntax starts with var <variable name> in LINQ

4) when and where do we use dictionary (generics ) particulary?

5) what are the different types of casting available in C#?

-Thanks




Responses

Posted by: Akiii on: 6/14/2012 [Member] Bronze | Points: 25

Up
0
Down
(1) We don't have to clear managed resources because the garbage collector takes care of that. But un-managed resources like connection object, file handler etc cannot be cleared by garbage collector. It is the sole duty of the programmer to explicitly clear those references if its not needed.

(2) sqlconn.close() - you are just closing the connection object. Here, the garbage collector will dispose the object for you.
sqlconn.Dispose() - here you are explicitly de-referencing the connection object from the memory heap.

(4) We need dictionary generic collection when we need key based search. using generics will help us to have strongly typed collection.

(5) for casting please refer to - http://msdn.microsoft.com/en-us/library/ms173105.aspx

I also don't know all these things, so please if anyone can help with the above questions !


Thanks and Regards
Akiii

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/15/2012 [Member] Starter | Points: 25

Up
0
Down
Garbage Collector :
In C#, the deallocation or freeing of resources consumed by created instances occurs automatically on a system-determined schedule by an intelligent mechanism known as garbage collection. The Garbage Collector (GC) is like a sweeper fish in an aquarium. If you drop more food than the other fish can eat, the sweeper fish consumes the remaining food without leaving any behind.

sqlcon.close() and sqlcon.dispose();
The basic difference between Close() and Dispose() is, when a Close() method is called, any managed resource can be temporarily closed and can be opened once again. It means that, with the same object the resource can be reopened or used. Where as Dispose() method permanently removes any resource ((un)managed) from memory for cleanup and the resource no longer exists for any further processing.

No idea about third question
when and where do we use dictionary (generics ) particulary?
When you have to keep key and value both.
what are the different types of casting available in C#?

http://www.dotnetperls.com/cast

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 6/15/2012 [Member] Bronze | Points: 25

Up
0
Down
@Perfect.Chourasia@Gmail.Com...........good answer regarding sqlcon.close() and sqlcon.dispose().



Thanks and Regards
Akiii

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response