|
INTERVIEW QUESTIONS
MICROSOFT
C#
DETAILS
Question: How do I get deterministic finalization in C#?
Answer: In a garbage collected environment, it's impossible to get true determinism. However, a design pattern that we recommend is implementing IDisposable on any class that contains a critical resource. Whenever this class is consumed, it may be placed in a using statement, as shown in the following example: using(FileStream myFile = File.Open(@"c:temptest.txt", FileMode.Open)) { int fileOffset = 0; while(fileOffset < myFile.Length) { Console.Write((char)myFile.ReadByte()); fileOffset++; } } When myFile leaves the lexical scope of the using, its dispose method will be called.
|
|
|
Category |
C# Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9898 users |
Added on |
10/24/2009 |
Views |
75490 |
Rate it! |
|
|
Question:
How do I get deterministic finalization in C#?
Answer:
In a garbage collected environment, it's impossible to get true determinism. However, a design pattern that we recommend is implementing IDisposable on any class that contains a critical resource. Whenever this class is consumed, it may be placed in a using statement, as shown in the following example: using(FileStream myFile = File.Open(@"c:temptest.txt", FileMode.Open)) { int fileOffset = 0; while(fileOffset < myFile.Length) { Console.Write((char)myFile.ReadByte()); fileOffset++; } } When myFile leaves the lexical scope of the using, its dispose method will be called. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How do I convert a string to an int in C#?
|
View Answer
|
|
Is there an equivalent of exit() for quitting a C# .NET application?
|
View Answer
|
|
How does one compare strings in C#?
|
View Answer
|
|
What is the difference between a struct and a class in C#?
|
View Answer
|
|
How can I get the ASCII code for a character in C#?
|
View Answer
|
|
Is it possible to inline assembly or IL in C# code?
|
View Answer
|
|
If I return out of a try/finally in C#, does the code in the finally-clause run?
|
View Answer
|
|
Does C# support try-catch-finally blocks?
|
View Answer
|
|
Is it possible to have a static indexer in C#?
|
View Answer
|
|
What optimizations does the C# compiler perform when you use the /optimize+ compiler option?
|
View Answer
|
|
How can I access the registry from C# code?
|
View Answer
|
|
Does C# support #define for defining global constants?
|
View Answer
|
|
Is there any sample C# code for simple threading?
|
View Answer
|
|
Is there regular expression (regex) support available to C# developers?
|
View Answer
|
|
Why do I get a security exception when I try to run my C# app?
|
View Answer
|
|
Does C# support parameterized properties?
|
View Answer
|
|
How do you inherit from a class in C#?
|
View Answer
|
|
Does C# support multiple inheritance?
|
View Answer
|
|
Describe the accessibility modifier protected internal.
|
View Answer
|
|
C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
|
View Answer
|