GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Microsoft  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 29 of 431    Print  

How do I get deterministic finalization in C#?

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.


  
Total Answers and Comments: 0 Last Update: N/A   
  
 Sponsored Links

 

No answers are posted for this question yet.
Be the first to answer it!


 Related Questions

All methods marked with the DllImport attribute must be marked as public static extern.  
Latest Answer : It works perfectly.  You can find the dialogue window by using "ALT+Tab" keyRobert  ...

C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#: switch(x){case 0:// do somethingcase 1:// do something in common with 0default:// 
Latest Answer : c# switch allows fall through if and only if in empty case. as long as there is a statement in the case it must  use break or go to to  jump out of the case. ...

The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant. To expand on the static read-only case 
Latest Answer : Constant : The constants are the one whose value remain same at all the time.it will be used if u want to define something at compile time.Read only....if you don't know value at compile time but u can find that at runtime that time u can use ...

Use a conditional attribute on the method, as shown below: class Debug{[conditional("TRACE")]public void Trace(string s){Console.WriteLine(s);}}class MyClass{public static void Main(){Debug.Trace("hello");}}In 
Latest Answer : if you are using conditinoal attribute then add the name spaceSystem.Diagnostics.ConditionalAttribute ...

You need to use the /target:library compiler option.  
Latest Answer : Open the property page of the Project File and thenopen CommonProperties -> Genaral ->Output Typechange the output type to class library and build the application then u'll get a dll file.also in the Configuartion Properties ->Build -> Output ...

The word checked is a keyword in C#.  
Latest Answer : Reason is checked is a keyword in C#,but if u want to keyword as an identifier use @ with it.e.g int @checked=3;This works with all the keywords,but it is recommended to avoid it. ...

What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?
The syntax for calling another constructor is as follows: class B{B(int i){ }}class C : B{C() : base(5) // call base constructor B(5){ }C(int i) : this() // call C(){ }public static void Main() {}}  

C# has the is operator: expr is type  
Latest Answer : EX:==============using System; class ClassA {} public class TestIs{   public static void Test (object o)    {      ClassA a = null;       if (o is ClassA)       ...

If you leave off the return type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that returns nothing, use void. The following 
Latest Answer : If your method does not have any return type then mention void before that method or return 0 ...

Strings are not null terminated in the runtime, so embedded nulls are allowed. Console.WriteLine() and all similar methods continue until the end of the string.  
Latest Answer : Console.WriteLine() stop printing when it reaches a 'Carriage Return' (denotes next line) character within a string! ...


 Sponsored Links

 
Related Articles

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

HR Interview - HR Interview Mistakes You Will Want To Avoid

HR Interview Mistakes You Will Want To Avoid The job interview can be a stressful process This is especially true for those who are going after a competitive position Your nonverbal communication combined with the answers you give during the interview will determine if you are hired mosgoogle While
 

HR Interview - Behavioral HR Interviews

Behavioral HR Interviews As the name implies a behavioral interview is an interview that is held by a human resources department to determine if an applicant has the behaviors that are appropriate for a job The company must know how an applicant will behave in a certain situations mosgoogle The logi
 

HR Interview - How To Prepare For Your HR Interview

How To Prepare For Your HR Interview Before you begin thinking about how you are going to dress for the interview it is important to do your research first You should learn everything you can about the company you wish to work for When you have detailed information about your employer you will conve
 

HR Interview - Telephone Interview Etiquette

Telephone Interview Etiquette When you conduct a telephone interview for a job it is important to show the proper etiquette Not only is it important it is critical is you wish to be hired by the company There are a number of things you will want to do and other things should never be done mosgoogle
 

HR Interview - How To Succeed At HR Interviews

How To Succeed At HR Interviews There are a number of things you will need to do in order to make sure you pass the interview process Your appearance is something that you will want to pay close attention to Even if you feel that your appearance shouldn t be a factor in whether or not you re highere
 

HR Interview - Do's and Dont's in a HR Interview

Do s and Dont s in a HR Interview There are a number of things that you will want to avoid during the HR interview process While some of these things are directed at the interviewer the other things are directed at the applicant If interviewers fail to follow the proper procedures throughout the int
 

HR Interview - HR Interview Tips

HR Interview Tips It has become more challenging for companies to find the right employees because of the market When you hold an interview for a potential employee there are a number of things you will want to keep in mind mosgoogle The goal of a company should be to hire an employee who can perfor
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape