Out Parameter Question
I think this should be simple, but I am coming up blank on a method call with an out parameter. (The example below is basic but my actual code requires the parameters)
File1.Cs
If I am trying to call the Position Method in File2.Cs
What do I put for the last parameter on p.Position?
6 Replies
out string s
for example
Or
or
s
can be any name
Alternatively, in this particular example... just return
that string, no need for an out
parameter
They're mostly used when you need a "second return"
Like in case of .TryParse()
methods that return a boolean denoting success, and use the out
param to return the parsed valueThank you so much. In my actual usage, I'm forced to return the out as a string variable because it's passed to parse depending on the values it contains. I was blanking hard on that one
Not sure what you mean here
I'm not aware of anything that would force you into having an out parameter
Unless you need to assign this method to some
Action<int, int, string>
But I don't think out
params work with delegatesAhh - I see. I left a lot of context out in my example, but in my program I'm using a custom dll wrapper that I'm unable to adjust the parameters that are requried to be passed. By nature of usage, there should alwyas be a string output else we won't even get to call this method
Ah, gotcha
That's a weird design on that dll's part, but needs must
Oh god you have no clue 💀