Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
getData(string connString, string ProcName, DataSet dsData=null)

//third parameter is optional
Posted
Updated 22-Jul-11 4:47am
v2
Comments
[no name] 22-Jul-11 10:44am    
What is your question?

Just use the parameter as if it was present - in your example, the method can be called in two ways:
getData("Hello", "There");
In which case dsData will be null when the method is executed, or
getData("Hello", "There", myDataSet);
in which case dsData will contain a DataSet when the method is executed.
 
Share this answer
 
I would suggest please have a look following links,

c-4.0-optional-parameters.aspx[^]

and Eric Lippert discuss about Optional parameter in his blog.

optional-argument-corner-cases-part-one.aspx[^]

Hope it helps :)
 
Share this answer
 
Does this answer your INCOMPLETE question?

string connString = 'whatever';
string procName = 'IDontKnow';

getDate(connString, procName);

Dataset dataset = null; 

getDate(connString, procName, dataset);


if you look at the code, the first call does not contain dataset as paramter. But when the function is called, it is impliclty considered as null (not because it not passed, but its default value has been specified as null).

Overall, the two calls here will give you same result; even though looking at code it differs.
 
Share this answer
 
v2
You use function overloading.
or another way you write your code like:-
 getData(string connString, string ProcName, DataSet dsData)
 {
if(dsData==null)
{
//wirte your code
}
else
{
//write your code.
}
}
 
Share this answer
 
Comments
Philippe Mori 22-Jul-11 20:26pm    
Effectively, if your code differs a lot, it make sense to uses function overloading.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900