c# - Is there any way to make a method with more than one instance? -
this question has answer here:
private void extractions(string htmlfilename, int offlinefilenumber, bool onlineoffline) { if (onlineoffline == false) { offlinedownload.offhtmlfiles(); page = offlinedownload.offlinefiles[offlinefilenumber]; byte[] bytes1 = file.readallbytes(page); page = encoding.getencoding(1255).getstring(bytes1); textextractor.getdatetimelist(page); streamwriter w = new streamwriter(@"c:\temp\" + htmlfilename);//@"d:\rotterhtml\rotterscoops.html"); w.write(page); w.close(); extractlinks.links(@"c:\temp\" + htmlfilename); textextractor.extracttext(@"c:\temp\" + htmlfilename, newtext); } else { client.encoding = system.text.encoding.getencoding(1255); page = client.downloadstring("http://rotter.net/scoopscache.html"); textextractor.getdatetimelist(page); streamwriter w = new streamwriter(@"d:\rotterhtml\rotterscoops.html"); w.write(page); w.close(); extractlinks.links(@"d:\rotterhtml\rotterscoops.html"); textextractor.extracttext(@"d:\rotterhtml\rotterscoops.html", newtext); } }
if user calls method want him have 2 options call 3 variables:
string htmlfilename, int offlinefilenumber, bool onlineoffline
or call without variables , if it's () automatic true.
you can "overload" method. have same name multiple parameter signatures.
private void extractions() { }
since method "void", don't know mean " if it's () automatic true."
unless meant was:
private void extractions(string htmlfilename, int offlinefilenumber) { extractions(htmlfilename, offlinefilenumber, true); }
of course make offline paremeter optional , give default of true.
private void extractions(string htmlfilename, int offlinefilenumber, bool onlineoffline = true) { .... }
Comments
Post a Comment