Reputation: 1207
Ref and out can change the behavior of function parameters. Sometimes we want the actual value of a variable to be copied as the parameter. Other times we want a reference. These modifiers affect definite assignment analysis.
My question is: can partial methods in C# have ref, out, optional input parameters?
Upvotes: -6
Views: 817
Reputation: 11959
By experimentation with the code in this example it seems like you can find that it is possible to use ref
, params
, and default argument values, but not out
partial class A
{
partial void OnSomethingHappened(string s);
partial void useRef(ref string s);
partial void useOpt(string s1, string s2 = null);
partial void useArgs(params string [] s);
}
// This part can be in a separate file.
partial class A
{
// Comment out this method and the program
// will still compile.
partial void OnSomethingHappened(String s)
{
Console.WriteLine("Something happened: {0}", s);
}
}
Also, as explained by the docs linked by @user6144226 and pointed out by @marc_s:
Partial methods can have ref but not out parameters.
Upvotes: 1