.net - C# -delegate array - how to add tostring methods -
is possible add tostring methods array of delegates?? if how?? here code have written:
public delegate string task(); public static void main(string[] args) { arraylist studentarray = new arraylist(); course italiancook = new italiancookcourse { teacher = "ben hodd" }; course seafoodcook = new seafoodcookcourse { teacher = "harry cotter"}; course sewingcourse = new sewingcourse { teacher = "margaret mair", chargeperstudent = scfee, costperstudent = 100.00m, }; course creativewrite = new creativewritcourse { teacher = "mary smith }; course businesswrite = new businesswritcourse { teacher = "mary smith" }; task[] tasks = new task(italiancook.tostring, seafoodcook.tostring, sewingcourse.tostring); the error message "string class.tostring()" - "method name expected"
as tostring method handle string, possible add delagate??
assuming fixed syntax, solution remove ()'s end of tostring's. create delegate based on method, need give name.
task[] tasks = new task[] { class1.tostring, class2.tostring } note above code does not compile. tostring() not static method, need pass in object reference along function name:
object o = new object(); task[] tasks = new task[] { o.tostring };
Comments
Post a Comment