-
April 4th, 2010, 05:32 PM
#1
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.
-
April 4th, 2010, 11:45 PM
#2
Re: Constructors...
Originally Posted by MajikOne
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.
-
April 5th, 2010, 12:03 AM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|