I was doing an assessment and this is one of the questions I got:
Which of the following changes cannot be made to the declaration of the C# method call(docume
As the last one is causing confusion, this might help.
public class Document
{
public void SaveAs(ref string DocName)
{
}
}
Notice the parameter name is DocName
. Usually this parameter name is thought of as something only used by the method and unimportant outside the method, but since .NET 4 (I think?), C# can used named parameters in this format. If you're familiar with Objective-C then you'll see these often. With named parameters, DocName
is important.
We can now call this method like this
string fName = "Test.docx";
Document d = new Document();
d.SaveAs(DocName: ref fName);
Note that DocName
has to be used, otherwise the compiler will thrown an error (so you couldn't do d.SaveAs(RandomName: ref fName);
). Also note that a string variable is passed and not instantiated within the method declaration (d.SaveAs(DocName: "Test.docx");
).
Replace object missing = Missing.Value; with object Missing Remove : will give an error, use of unassigned local variable
object fileName = "Test.docx" : : will give an error, use of unassigned local variable
The last two i have no idea about, horribly worded.