473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How do I create a class item with properties?

mb
Here is an example of what I want to create:

A class called Cars

public class Cars
{
public string Mazda;
public string Ford;
etc, etc..........
}

then I want to create properties for each car so if I instantiate Cars:

Cars myCar = new Cars();

then I can access this:

myCar.Mazda.Wheels = Color.Black

I hope this makes sense.

Thanks

PS. I want to randomly pick a car and have its Wheel property checked.
Jul 21 '05 #1
4 1355
What you're talking about is class inheritance.
something like:

public class Cars
{
public System.Drawing.Color Wheels;
}

public class Mazda : Cars
{

}

public class Ford : Cars
{

}

Imran.

"mb" <mm@hotmail.com> wrote in message
news:uh*************@TK2MSFTNGP12.phx.gbl...
Here is an example of what I want to create:

A class called Cars

public class Cars
{
public string Mazda;
public string Ford;
etc, etc..........
}

then I want to create properties for each car so if I instantiate Cars:

Cars myCar = new Cars();

then I can access this:

myCar.Mazda.Wheels = Color.Black

I hope this makes sense.

Thanks

PS. I want to randomly pick a car and have its Wheel property checked.

Jul 21 '05 #2
mb
Thanks,

I see how that would work, yet I would have to individually instanciate
every car if I awas to use them all.
I want to just instaniate a Car, pick the car I want from the list of
properties, then pick a property of a property. Is this not possible?
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
What you're talking about is class inheritance.
something like:

public class Cars
{
public System.Drawing.Color Wheels;
}

public class Mazda : Cars
{

}

public class Ford : Cars
{

}

Imran.

"mb" <mm@hotmail.com> wrote in message
news:uh*************@TK2MSFTNGP12.phx.gbl...
Here is an example of what I want to create:

A class called Cars

public class Cars
{
public string Mazda;
public string Ford;
etc, etc..........
}

then I want to create properties for each car so if I instantiate Cars:

Cars myCar = new Cars();

then I can access this:

myCar.Mazda.Wheels = Color.Black

I hope this makes sense.

Thanks

PS. I want to randomly pick a car and have its Wheel property checked.


Jul 21 '05 #3
MB,
I see how that would work, yet I would have to individually instanciate
every car if I awas to use them all.
I want to just instaniate a Car, pick the car I want from the list of
properties, then pick a property of a property. Is this not possible?
In a general way answered, the answer is "No, this is possible" but than you
should create a property "brand" and pass that in your New constructor.

Did you know that for language questions about C# is the very active
newsgroup.
Microsoft.public.dotnet.languages.csharp

I hope this helps?

Cor

"mb" <mm@hotmail.com>
... Thanks,

I see how that would work, yet I would have to individually instanciate
every car if I awas to use them all.
I want to just instaniate a Car, pick the car I want from the list of
properties, then pick a property of a property. Is this not possible?
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
What you're talking about is class inheritance.
something like:

public class Cars
{
public System.Drawing.Color Wheels;
}

public class Mazda : Cars
{

}

public class Ford : Cars
{

}

Imran.

"mb" <mm@hotmail.com> wrote in message
news:uh*************@TK2MSFTNGP12.phx.gbl...
> Here is an example of what I want to create:
>
> A class called Cars
>
> public class Cars
> {
> public string Mazda;
> public string Ford;
> etc, etc..........
> }
>
> then I want to create properties for each car so if I instantiate Cars:
>
> Cars myCar = new Cars();
>
> then I can access this:
>
> myCar.Mazda.Wheels = Color.Black
>
> I hope this makes sense.
>
> Thanks
>
> PS. I want to randomly pick a car and have its Wheel property checked.
>
>



Jul 21 '05 #4
MB,

I believe the way is:
1. Create a car collection or hashtable and use car name as index.
2. Add the cars you need.
3. Use the syntax like
mycars["Mazda"] = Color.Black or
mycars[CarType.Mazda] = Color.Black

Yang Lu.

"mb" wrote:
Thanks,

I see how that would work, yet I would have to individually instanciate
every car if I awas to use them all.
I want to just instaniate a Car, pick the car I want from the list of
properties, then pick a property of a property. Is this not possible?
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
What you're talking about is class inheritance.
something like:

public class Cars
{
public System.Drawing.Color Wheels;
}

public class Mazda : Cars
{

}

public class Ford : Cars
{

}

Imran.

"mb" <mm@hotmail.com> wrote in message
news:uh*************@TK2MSFTNGP12.phx.gbl...
Here is an example of what I want to create:

A class called Cars

public class Cars
{
public string Mazda;
public string Ford;
etc, etc..........
}

then I want to create properties for each car so if I instantiate Cars:

Cars myCar = new Cars();

then I can access this:

myCar.Mazda.Wheels = Color.Black

I hope this makes sense.

Thanks

PS. I want to randomly pick a car and have its Wheel property checked.



Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Migrant | last post by:
Hi Friends; I want develop a group logic with C# (n tier refraction).I know I must create a Class and inherit it But I don't have enough know-how about develop classes. Somebody can help me? ...
4
by: mb | last post by:
what is the best way to do this: In a game I want to a class called "Items". This class will have the game items public class Items { public int Chair public int Table . . .and so on . . .
7
by: Peter | last post by:
I want to create a multidemensional arraylist. Seeing as they don't exist I was wondering if there is a way to create a class that works like one. I basically want to use it like this Dim...
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
4
by: mb | last post by:
Here is an example of what I want to create: A class called Cars public class Cars { public string Mazda; public string Ford; etc, etc.......... }
1
by: drk.kumar | last post by:
I have an implementation issue with WMI scripts to check the user machine processor. The implementation is working fine in the local machine (Windows XP operating system). It is throwing script...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
3
by: Steve Richter | last post by:
when enumerating thru the properties of a type, how do I select only the properties of the derived class? In the example below, the AddrBookPrompt class is derived from the Form class. When I...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.