Reputation: 2551
I have a function like this :
example(long a,long b,string c,DateTime d,DateTime e,out decimal f)
when i am trying to call it i am doing this :
long a =1;
long b=2;
string c="";
DateTime d=DateTime.Now;
DateTime e=DateTime.Now;
decimal f=0;
example(a,b,c,d,e,f) --> Here is giving me the error : the best overloaded method has some invalid argument
can you please help me fix this problem
Upvotes: 1
Views: 52
Reputation: 460228
Since d
is an out
parameter you need the out
keyword (in C#):
example(a, b, c, d, e, out f)
Upvotes: 1
Reputation: 98830
You should use out
keyword also when you calling your method like;
example(a,b,c,d,e, out f);
From MSDN
;
The out keyword causes arguments to be passed by reference. This is like the ref keyword, except that ref requires that the variable be initialized before it is passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword.
Upvotes: 0
Reputation: 116528
You need to use the out
keyword in your method call as well:
example(a, b, c, d, e, out f);
See also: out parameter modifier (C# Reference)
Upvotes: 0
Reputation: 273524
You need to call example(a,b,c,d,e, out f);
And there is no need to initialize f
, and it is better not to do so (it's misleading):
//decimal f=0;
decimal f;
Upvotes: 3