On Virtual And Override
-
Hi Folks Hope you all are having a good knowldze on C#. Here i want to know one thing , At runtime how runtime will decide what to use I mean either virtual one or overrided one. two more Question What is the difference between Abstract class and interface We know some basic differences. when to use structures and when to use classes Praveen Chintamani.
-
Hi Folks Hope you all are having a good knowldze on C#. Here i want to know one thing , At runtime how runtime will decide what to use I mean either virtual one or overrided one. two more Question What is the difference between Abstract class and interface We know some basic differences. when to use structures and when to use classes Praveen Chintamani.
praveenc80 wrote: At runtime how runtime will decide what to use I mean either virtual one or overrided one. That is polymorphism, the compiler will take care of that for you. Whatever your object "is a" instance of will be called. praveenc80 wrote: What is the difference between Abstract class and interface Abstract class can't be instantiated. Interface is good to use if you want to enforce a method on certain objects, but those objects might not have a base->child relationship. For example, look at IDisposable, Microsoft classes that implemenet this interface support the Dispose() method to cleanup resources. praveenc80 wrote: when to use structures and when to use classes Your call really. Structures are stored on the stack and classes are on the heap. Strcutures are not as powerful as classes, but are more quickly accessed from memory. I could imagine using structs for something not so object oriented. Hope this gives you a starting point.
R.Bischoff .NET, Kommst du mit?
-
praveenc80 wrote: At runtime how runtime will decide what to use I mean either virtual one or overrided one. That is polymorphism, the compiler will take care of that for you. Whatever your object "is a" instance of will be called. praveenc80 wrote: What is the difference between Abstract class and interface Abstract class can't be instantiated. Interface is good to use if you want to enforce a method on certain objects, but those objects might not have a base->child relationship. For example, look at IDisposable, Microsoft classes that implemenet this interface support the Dispose() method to cleanup resources. praveenc80 wrote: when to use structures and when to use classes Your call really. Structures are stored on the stack and classes are on the heap. Strcutures are not as powerful as classes, but are more quickly accessed from memory. I could imagine using structs for something not so object oriented. Hope this gives you a starting point.
R.Bischoff .NET, Kommst du mit?
Soliant wrote: Abstract class can't be instantiated. Interfaces are also nice because a class can only extend one other class. If you use abstract classes and need to inherit additional functionality (say, from
Control
), you won't be able to because you're already extending one abstract base class. This is where interfaces come in handy because you an implement more than one interface. Soliant wrote: I could imagine using structs for something not so object oriented. Structures should really only be used for small amounts of short-lived data, such as aSize
or aPoint
(both used to position and size a control, but then aren't needed again things change).Microsoft MVP, Visual C# My Articles