GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 17 of 436    Print  

I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?

You should declare the variable as an int, but when you pass it in you must specify it as 'out', like the following:

int i;

foo(out i);

where foo is declared as follows:

[return-type] foo(out int o) { }


  
Total Answers and Comments: 3 Last Update: August 15, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: bhavkins
 

It is true that you use out when you don't want to initialise the variable and force the called function to initialise and assign proper value.

But this mechanism doesn't stop you from initialising the variable you are passing with out parameter.
The only thing the compiler forces is to initialise the variable inside the function.



Above answer was rated as good by the following members:
Wise Man
January 06, 2006 09:50:30   #1  
sahu Member Since: December 2005   Contribution: 323    

RE: I was tr...

ans:

Definition:

Out

A parameter declared with an out modifier is an output parameter.

A variable must be definitely assigned before it can be passed as a reference parameter in a function member invocation. A variable must be definitely assigned before it can be passed as a reference parameter in a function member invocation.

example

int x 4

calling function

Functioname(out int x)


 
Is this answer useful? Yes | No
June 13, 2007 12:01:03   #2  
blue        

RE: I was tr...
You are wrong sahu .
You pass out parameters when you don't want to initialize the variable before entering a function. But the variable must be initialized within the function.

 
Is this answer useful? Yes | No
August 15, 2007 08:54:28   #3  
bhavkins        

RE: I was tr...

It is true that you use out when you don't want to initialise the variable and force the called function to initialise and assign proper value.

But this mechanism doesn't stop you from initialising the variable you are passing with out parameter.
The only thing the compiler forces is to initialise the variable inside the function.


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape