c# - Rename existing method returning void with input arguments -
maybe silly, i'm trying shorten calling of method streamwriter.writeline becasue have call many times throughout code. so, instead of calling myfile.writeline() write myfile.wl().
is possible?
after searching solution wrote this:
private static void wl(this streamwriter myfile, params string mystring) { return (void)myfile.writeline(mystring); } but error
cannot convert type 'void' 'void'
any ideas?
your extension method should be
private static void wl(this streamwriter myfile, params string mystring) { myfile.writeline(mystring); } reasons:
writelinemethod of streamwriter not return i.e. void. , quotewrites string followed line terminator text string or stream. should remove return keyword method. read here.
btw, extension method should public if want use outside of class define in.
Comments
Post a Comment