c# - Use object name to return value of a specific property -
is there method object name return specified property value variable. example have following class
class class1 { int valint; double valdouble; string valstring; public class1(int intvalue) { valint = intvalue; } public class1(double doublevalue) { valdouble = doublevalue; } public class1(string stringvalue) { valstring = stringvalue; } }
so when use object this
list<class1> list = new list<class1>(); list.add(new class1(25)); list.add(new class1(3.15)); list.add(new class1("name")); foreach (class1 item in list) { console.writeline(item); -> outputs 25, 3.15, name }
Comments
Post a Comment