Thursday 15 August 2013

c# - Trying to use virtual-like variable in abstract class instance -


I will supply the base class accessor functions should write how a class that I am trying to explain it and then Instasd Class only needs to supply values

Something like this:

  Public Interface IBaseClass {int GetHandlerID (); } Public abstract class AbstractClass: IBaseClass {Private Int HandlerID; Public Virtual Ink GateHandlerId () {Return (This. HandlerId); }} Public Class Mayclass: Abstracts {Int Handleri = 1; } Class program {static zero main (string [] args) {MyClass newClass = new MyClass (); Console WrightLine ("HandlerID: {0}"), newClass.GetHandlerID ()); }} Is   

It does not work that way because Class Heclayraidi want to read instead Aebstrak class of MyClass variable. The use of virtual or abstract is not valid for variables, so I'm not sure how to do this apart from implementing a new class turned out properties.

I'm trying to do, people are able to supply the interface to create their own plug-in class and access will use the class which is supplied with the base class . Whenever I make a new example of class, I still do not want to apply the same property method.


I thought one way to do what I wanted to do In this way, I can do default gates / sets in base class and they do not have to make them in every definition that uses the base. It's not quite what I was searching for, but it will work.

  Public abstract class AbstractClass: IBaseClass {Private int m_HandlerID = 0; Receive public Int Hendlraidi {to (return (this.m_HandlerID);} set {this.m_HandlerID = value;}} private string m_HandlerDescription = "undefined"; public string handler Get description {this.m_HandlerDescription;} set {this.m_HandlerDescription = value;}}} public class Maiklas: Abrclos {public Maiklas () {Handlraidi = 1; handler description = "Maiklas";}} class program {static void main (string [] Arges) {MyClass newClass = new MyClass () ; Console.lightline ("handler: {0 } [{1}] ", Nvclaskhndlerdeskripshn, Nvclaskhandlerid);}}    

< Pre> Public abstract class AbstractClass: IBaseClass {public AbstractClass (int handlerId)} {This.HandlerId = handlerId; } Public Entry Handelder () {Return (This Handler ID); }} Public Classes Mylus: Aberclass {Public Mylly (): Base (1) // Specific Handler ID}

How is the value passing through a base constructor < / Div>

No comments:

Post a Comment