Extension objects to a class -
well discovered extension methods, extension methods allow extending methods , functionality existing type without needing change code : here
// extending using extension methods static class myextensionmethods { public static int negate(this int value) { return -value; } } static void main(string[] args) { //using extension method int i2 = 53; console.writeline(i.negate()); }
my question :
is possible same thing object, example add int id form, can :
form frm = new form(); frm.id = 2;
yes, can create extension methods on type of class want.
however, example not method property , cannot create extension properties.
the following valid:
static class formextensions{ public static void setid(this form form, int someid) { // someid here } } // call this: form frm = new form(); frm.setid(2);
Comments
Post a Comment