CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Constructors...

  1. #1
    Join Date
    Apr 2010
    Posts
    3

    Constructors...

    Hi everybody
    I'm new to c# and need your help in this assignement please.
    I have 2 super class and 1 subclass, I need to use a constructor parameter from class 2 in the subclass 1, is that possible in C#.

    namespace AAA_Class_Object
    {
    class Person
    {
    private string name;
    public Person(string name)
    { this.name = name; this.status = status; }
    }
    }

    namespace AAA_Class_Object
    {
    class Article
    {
    private string type;
    public Article(string type)
    { this.type = type; }
    }
    }

    namespace AAA_Class_Object
    {
    class CDs : Article
    {
    public CDs(string cdName, string type, Person name) : base (type)
    {..................}
    }
    }

    So, is it possible to use name of Person constructor in the CDs constructor.
    How please???

    Thanks in advance.

  2. #2
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: Constructors...

    Quote Originally Posted by MajikOne View Post
    namespace AAA_Class_Object
    {
    class CDs : Article
    {
    public CDs(string cdName, string type, Person name) : base (type)
    {..................}
    }
    }

    So, is it possible to use name of Person constructor in the CDs constructor.
    How please???
    You are already passing a Person object in CDs class. So, you can just store the instance in a private variable of type Person. Alternatively, if you intended to pass a string which is a person name, then you can create a person object from it using
    Code:
    myPerson = new Person(personName);
    This code will go in the CDs constructor with myPerson being a private variable of type Person.

  3. #3
    Join Date
    Apr 2010
    Posts
    3

    Re: Constructors...

    Thanks Rohshal... it worked...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured