Saturday, 15 June 2013

c# - Can I change a base class object to a derived class object from inside the base class? -


Actually, I want to do something like this:

  public class A {public zero AddData (byte [] data) {// analyze data if (BoolFromAnalyzedData == true) {AFirstType a = new AFSTType (); A.SomeInt = IntFromAnalyzedData; This = a; } Else {ASecondType a = new ASecondType (); A.SomeString = StringForm Analyzed Data; This = a; }}} Public Category AFTERType: A {public int SomeInt; } Public Class Eskkend Type: A {public string Some strings; }   

Then, I want to be able to:

  a.AddData (data); If (AAST type) dustf (as an ASFType) .SomeInt); And if (a escond type) dustf ((AS ASKCAND type). Some strings);   

I have a class and after that there are two separate classes with different properties. When I make the base class, I do not know how it should be, I Only can understand how it is late when I get some data and analyze it. Again, I want to be able to check how it is and use the derived class properties.

The problem is, I can not get into this C #, so how can I use the option?

I think you should change your attitude towards the problem.

Combining your unit (which stores data) with your hydration code (which populates them).

You should separate 2 behaviors and, perhaps, depending on the specific type of A the data you provide.

  Public category A {// general content} Public category AFTERType: A {public Int SomeInt {get; Set;}} Public category Escand type: A {public string string {get; Set;}} Public Category FT {public static zero (byte [] data) {// analyze data if (bulflame ANligged data is true ==) {typing new forefront ({{SomeInt = IntFromAnalyzedData}; } And {type new escondition ({{SomeString = StringFromAnalyzedData}; }}} /// Main Code Byte [] Data = Gate Data (); An AA = forex. Create (data); If (AAST type) dustf (as an ASFType) .SomeInt); And if (a escond type) dustf ((AS ASKCAND type). Some strings);    

No comments:

Post a Comment