Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Class Inheritance

Class Inheritance

Scheduled Pinned Locked Moved C#
csharpdelphialgorithmsoophelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gareth_Hastings
    wrote on last edited by
    #1

    I'm just starting to get my teeth in to C# and so far I think its going quite well. I used to do quite a bit of coding in Delphi which brings me on to my current problem. In Delphi you used to be able to create your own class using a Thread class as its base example: -------------------------------- TMyClass = Class(TThread) .... Public FVariable : string; End; Var MyClass : TMyClass; MyClass := TMyClass.Create(True); MyClass.FVariable := 'Test'; -------------------------------- MyClass now has all the functions/procedures and variables of a normal thread class. I would like to do the same thing in C# but I can't inherit from system.threading.thread because it's sealed. I suspect there might be another approach to this but I can't find much on google. I guess I am not searching for the right things here. I guess I'm trying to do this the Delphi way when I should be doing them the C# way!!! Any ideas anyone? Thanks

    D N 2 Replies Last reply
    0
    • G Gareth_Hastings

      I'm just starting to get my teeth in to C# and so far I think its going quite well. I used to do quite a bit of coding in Delphi which brings me on to my current problem. In Delphi you used to be able to create your own class using a Thread class as its base example: -------------------------------- TMyClass = Class(TThread) .... Public FVariable : string; End; Var MyClass : TMyClass; MyClass := TMyClass.Create(True); MyClass.FVariable := 'Test'; -------------------------------- MyClass now has all the functions/procedures and variables of a normal thread class. I would like to do the same thing in C# but I can't inherit from system.threading.thread because it's sealed. I suspect there might be another approach to this but I can't find much on google. I guess I am not searching for the right things here. I guess I'm trying to do this the Delphi way when I should be doing them the C# way!!! Any ideas anyone? Thanks

      D Offline
      D Offline
      Dmitriy Kostovetskiy
      wrote on last edited by
      #2

      In C# threads are handled differently. You create an instance of System.Threading.Thread and pass ThreadStart delegate to the constructor. ThreadStart delegate represents a method that thread will run.

      public static void RunMe()
      {
      {
      //Run code here
      }
      }

      public static Main()
      {
      Thread myTread = new Thread(new ThreadStart(RunMe));
      }

      1 Reply Last reply
      0
      • G Gareth_Hastings

        I'm just starting to get my teeth in to C# and so far I think its going quite well. I used to do quite a bit of coding in Delphi which brings me on to my current problem. In Delphi you used to be able to create your own class using a Thread class as its base example: -------------------------------- TMyClass = Class(TThread) .... Public FVariable : string; End; Var MyClass : TMyClass; MyClass := TMyClass.Create(True); MyClass.FVariable := 'Test'; -------------------------------- MyClass now has all the functions/procedures and variables of a normal thread class. I would like to do the same thing in C# but I can't inherit from system.threading.thread because it's sealed. I suspect there might be another approach to this but I can't find much on google. I guess I am not searching for the right things here. I guess I'm trying to do this the Delphi way when I should be doing them the C# way!!! Any ideas anyone? Thanks

        N Offline
        N Offline
        Nick Parker
        wrote on last edited by
        #3

        If you are looking for the syntax of classes for C#, the following is a simple example:

        public class TrafficLight
        {
        // constructor
        TrafficLight(){}

        // private variable
        private Color \_color; 
        
        // public property
        public Color LightColor
        {
           get{return \_color;}
           set{\_color = value;}
        }
        
        public virtual void ChangeColor(Color newColor)
        {
            LightColor = newColor;
        }
        

        }

        public class DeluxeLight : TrafficLight
        {
        // constructor
        DeluxeLight(){}

        public overrides void ChangeColor(Color myColor)
        {
           //.... overriding the base class method
        }
        

        }

        - Nick Parker
          My Blog

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups