ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Microsoft Related  >>  C Sharp
 
 


 

 
 Visual Basic interview questions  Visual Basic Interview Questions
 C Sharp interview questions  C Sharp Interview Questions
 ASP.NET interview questions  ASP.NET Interview Questions
 VB.NET interview questions  VB.NET Interview Questions
 COM+ interview questions  COM+ Interview Questions
 ADO.NET interview questions  ADO.NET Interview Questions
 IIS interview questions  IIS Interview Questions
 MTS interview questions  MTS Interview Questions
 Crystal Reports interview questions  Crystal Reports Interview Questions
 BizTalk interview questions  BizTalk Interview Questions
 Dot Net interview questions  Dot Net Interview Questions
 Exchange Server interview questions  Exchange Server Interview Questions
 Microsoft Related AllOther interview questions  Microsoft Related AllOther Interview Questions
Question
what is reference parameter?
what is out parameters?
what is difference these two?
 Question Submitted By :: Somavenki
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is reference parameter? what is out parameters? what is difference these two?
Answer
# 1
a ref parameter must first be initialized before being 
passed from the calling function to the called function.


but a out parameter need not be initialized, we can pass it 
directly
 
Is This Answer Correct ?    4 Yes 1 No
Anna
 
  Re: what is reference parameter? what is out parameters? what is difference these two?
Answer
# 2
normally while we are passing values to other methods it 
will pass copy of the values.But we use ref or out 
parameter it pass reference of values.
 
Is This Answer Correct ?    0 Yes 0 No
Aravazhi
 
 
 
  Re: what is reference parameter? what is out parameters? what is difference these two?
Answer
# 3
When we pass a parameter as ref to a method, the method 
refers to the same variable and changes made will affect 
the actual variable. even the variable passed as out 
parameter is same as ref parameter, but implementation in 
c# is different, 
Arguement passed as ref parameter must be initialized 
before it is passed to the method. But in case of out 
parameter it is not necessary. But after a call to a method 
as out parameter it is necessary to initialize.
When to use out and ref parameter, out parameter is used 
when we want to return more than one value from a method.
 
Is This Answer Correct ?    0 Yes 0 No
Lakshmi
 
  Re: what is reference parameter? what is out parameters? what is difference these two?
Answer
# 4
Ref parameter can be used as both input and o/p parameter
out parameter can be used as only output parameter
 
Is This Answer Correct ?    3 Yes 0 No
Rvs Varma
 
  Re: what is reference parameter? what is out parameters? what is difference these two?
Answer
# 5
The main difference between them is ref parameter act as 
input/output  whereas out parameter is simply act as output.

Let us understand with an example:

Out parameters "out" parameters are output only parameters 
meaning they can only passback a value from a function.We 
create a "out" parameter by preceding the parameter data 
type with the out modifier. When ever a "out" parameter is 
passed only an unassigned reference is passed to the 
function. 

using System;
class Test
{
 static void out_test(out int x)
 {
  x=100;
 }
 static void Main()
 {
  int Myvalue=5;
  MyMethod(Myvalue);
  Console.WriteLine(out Myvalue);             
 }
}

Output of the above program would be 100 since the value of 
the "out" parameter is passed back to the calling part. 
Note 
The modifier "out" should precede the parameter being 
passed even in the calling part. "out" parameters cannot be 
used within the function before assigning a value to it. A 
value should be assigned to the "out" parameter before the 
method returns. 

Ref parameters "ref" parameters are input/output parameters 
meaning they can be used for passing a value to a function 
as well as to get back a value from a function.We create 
a "ref" parameter by preceding the parameter data type with 
the ref modifier. When ever a "ref" parameter is passed a 
reference is passed to the function. 

using System;
class Test
{
 static void Mymethod(ref int x)
 {
  x=x+ 100;
 }
 static void Main()
 {
  int Myvalue=5;
  MyMethod(Myvalue);
  Console.WriteLine(ref Myvalue);              
 }
}

Output of the above program would be 105 since the "ref" 
parameter acts as both input and output. 
Note 

The modifier "ref" should precede the parameter being 
passed even in the calling part. "ref" parameters should be 
assigned a value before using it to call a method.
 
Is This Answer Correct ?    2 Yes 0 No
Piyush Sharma
 
  Re: what is reference parameter? what is out parameters? what is difference these two?
Answer
# 6
out -doesnot keep initial value or assigned value.
ref-does
void f1(out int t){
t+=100 //give error becs t has no value  --true for ref
t=100 //possible
}
 
Is This Answer Correct ?    1 Yes 1 No
Vijaysaxena
 

 
 
 
Other C Sharp Interview Questions
 
  Question Asked @ Answers
 
What is the Difference between a sub and a function? Wipro3
If all code is written in a try block and write a catch block with Exception type Exception .In that scenario will all the exceptions catched by that catch block? or any exceptions which will not be caught? Honeywell2
What are object oriented concepts? Microsoft2
write code for Factorial? Tech-Mahindra4
what r arraylist? what the use of Hashtables?  4
What is short circuit logical evaluation? TCS1
What is the difference between readonly and constant in c# Fulcrum-Logic1
Can you declare the override method static while the original method is non-static?  2
Can you prevent your class from being inherited and becoming a base class for some other classes?  2
What is overloading and how can this be done ? MMTS2
7. 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?  1
What?s the advantage of using System.Text.StringBuilder over System.String?  1
Does C# supports multi-dimensional arrays ? Microsoft3
How can we acheive inheritance in VB.NET ? TCS1
difference between keyword internal and protected? HCL4
ThreadStart is defined in the namespace System.Threading. What type of entity is ThreadStart?  1
how to use msflexgrid in asp.net Unichem1
What is a resource? Provide an example from your recent project. Wipro1
Which is the best institute in hyderabad to learn Sharepoint Portal?  1
how to use caching in our program. why we use it give one example in code  1
 
For more C Sharp Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com