c# - Optional function parameter with default value by reference -
by automatic conversion of code written in vb.net c# have such situation in function declaration of vb.net:
private function dataarchiver(byval toplace string, optional byval aextension string = ".7z", optional byref createdname string = "") integer
tool automatic conversion in c#:
private int dataarchiver(string toplace, string aextension = ".7z", ref string createdname = "")
and of course don't work. keyword "ref" before last argument underlined red. why so? because string createdname may (and don't have be) generated in function , in case have passed out function. important code can work net framework 3.5.
any idea working in c# without reconcepting of vb.net program?
you have create overloaded methods (as have had before c# acquired optional parameter feature):
private int dataarchiver(string toplace, string aextension) { string tempvar = ""; return dataarchiver(toplace, aextension, ref tempvar); } private int dataarchiver(string toplace) { string tempvar = ""; return dataarchiver(toplace, ".7z", ref tempvar); } private int dataarchiver(string toplace, string aextension, ref string createdname) { return 0; }
Comments
Post a Comment