polymorphism without classes in C# -


i new object-oriented programming. problem when define method in class, can use method in way:

myobj.mymethod(params); 

but don't want method member of class, still polymorphic function. mean, want "free" function different things based on parameters. example:

mymethod(myobjoftype1, intvar); // works ints mymethod(myobjoftype2, stringvar); // different function works strings 

is possible in c#?

to make 'independent method' not possible in c# since there class or member of class.

to problem recommend using static class have static methods.

usage:

classname.methodname(); 

all methods different parameters should implemented inside class (method overloading).

but if doesn't suit you, should have @ generic methods (but in case need create @ least 1 class).


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -