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 17 of 431    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

No best answer available. Please pick the good answer available or submit your answer.
January 06, 2006 09:50:30   #1  
sahu Member Since: December 2005   Contribution: 324    

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 | No


 
Go To Top


 Sponsored Links

 




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