Re: Private Constructor
From: Marcin Grzębski (mgrzebski_at_taxussi.no.com.spam.pl)
Date: 03/05/04
- Next message: Tristan: "Testing equality of pens"
- Previous message: Sami Vaaraniemi: "Re: Threading / random number problem"
- In reply to: Q2004: "Private Constructor"
- Next in thread: Marcin Grzębski: "Re: Private Constructor"
- Reply: Marcin Grzębski: "Re: Private Constructor"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 05 Mar 2004 11:53:51 +0100
Hi,
> What's the significant of private construtor ?
>
> public class Car{
> private string m_strName;
> private string m_strType;
> private int m_nID;
>
> private Car(string name, string type, int ID)
> {
> m_strName = name;
> m_strType = type;
> m_nID = ID;
> }
>
> public static string Name
> {
> get
> {
> return m_strName;
> }
> }
> }
>
> I intended to create an enumeration class similar to Color
> class in .NET framework.
>
> Color mycolor = Color.Blue;
>
> How should I modify the class above to make the following
> works ?
>
Car car = car.NISSAN;
???
I hope you mind:
Car car = Car.NISSAN;
Add this sample to code of your class, to accomplish your needs:
public readonly static NISSAN = new Car("Nissan"
, "small"
, 1);
Regards
Marcin
- Next message: Tristan: "Testing equality of pens"
- Previous message: Sami Vaaraniemi: "Re: Threading / random number problem"
- In reply to: Q2004: "Private Constructor"
- Next in thread: Marcin Grzębski: "Re: Private Constructor"
- Reply: Marcin Grzębski: "Re: Private Constructor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|