473,408 Members | 1,871 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,408 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 1359
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.