.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> C# >> Post New Question Subscribe to Interview Questions

Why do we need "out" parameters?

Posted By :Ravi Ranjan Kumar     Posted Date :June 24, 2011    Points :40   Category :C# 
we need out parameters because it enforce the contract between the caller and the callee (the function being called) by explicitly specifying that the callee will initialize them.

You can also find related Interview Question to Why do we need "out" parameters?  below: 

What is the difference between ref & out parameters?

  
An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter. (More...)

How do I simulate optional parameters to COM calls?

  
You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters. (More...)

what is the difference between ref and out parameters ?

  
Argument passed as ref must be initialized before it is passed to the method,where as incase of Out it's not neccssary.but after a call to the method as an out parameter the variable must be initialized .out parameter can be used when you want to return more than one value from a method. (More...)

can a constructor have parameters?

  
Yes, constructor can have parameters of their own.

also it can be overloaded.

public class myClass
{
public myClass()
{
// This is the no parameter constructor method.
// First Constructor
}

public myClass(int EmpID)
{
// This is the constructor with one parameter.
// Second Constructor

}

public mySampleClass(int EmpID, string Name)
{
// This is the constructor with two parameters.
// Third Constructor
}

(More...)

HOW TO ASSIGN VALUE TO PARAMETERS USED IN QUERY WHICH IS STORED IN A VARIABLE?

  
Have a look at the following sql block

DECLARE
/* @STRQUERY AND @PARAMDEF SHOULD BE NVARCHAR
BECAUSE "EXECUTE sp_executesql" ACCEPTS STATEMENT AND PARAMETER OF TYPE 'ntext/nchar/nvarchar' ONLY
OTHERWISE
"Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'."
OR
"Procedure expects parameter '@parameters' of type 'ntext/nchar/nvarchar'." WILL BE RAISED*/
@STRQUERY AS NVARCHAR(200),
@STRNAME AS VARCHAR(100),
@PARAMDEF AS NVARCHAR(100),
@STRNAMEVALUE AS VARCHAR(100)
BEGIN
--FOLLOWING STATEMENT ASSING VALUE
SET @STRNAMEVALUE='MANINDER'
--FOLLOWING VARIABLE CONTAINS A QUERY WHICH USES A PARAMETER
SET @STRQUERY = 'SELECT ''YOUR NAME IS '' + @STRNAME'

--FOLLOWING STATEMENT DEFINES THE PARAMETERS USED IN THE QUERY
SET @PARAMDEF = '@STRNAME AS VARCHAR(100)'

--IN THE FOLLOWING STATEMENT "@STRNAME = @STRNAMEVALUE" STATEMENT ASSIGNS VALUE TO THE PARAMETER
--SYNTAX IS EXECUTE sp_executesql @STATEMENT, @PARAMETERS
EXECUTE sp_executesql @STRQUERY, @PARAMDEF,@STRNAME = @STRNAMEVALUE;
END (More...)

Parameters used in Connection pooling

  
Connection Pooling is controlled and the parameters passed to a connection string comprises the following:

· Connect Timeout

· Min Pool Size

· Max Pool Size

· Pooling

(More...)

What is Difference between ref and out parameters in c#

  
A ref parameter:
has to be initialized by the caller.
does not have to be assigned in the function.
a ref parameter is for both input and output to the method

An out parameter:
does not have to be initialized by the caller.
has to be assigned in the function
an out parameter is only for output. (More...)

What are the Parameters used in Connection pooling

  
nnection Pooling is controlled and the parameters passed to a connection string comprises the following:

· Connect Timeout

· Min Pool Size

· Max Pool Size

· Pooling

(More...)

Difference between Ref vs Out Parameters?

  
ref parameter:
Ref is keyword.
it must be used along with actual and formal arguments.
ref variables must be initialized before passing to a function
out parameter:
It is very similar to call by Reference.
Out is a Keyword.
Which must be used along with actual and formal arguments.
Out variables are not require to initialize, the initialized value will not be passed, only reference will be passed. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend