Re: Private Constructor

From: Marcin Grzębski (mgrzebski_at_taxussi.no.com.spam.pl)
Date: 03/05/04


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



Relevant Pages

  • Private Constructor
    ... What's the significant of private construtor? ... I intended to create an enumeration class similar to Color ... Car car = car.NISSAN; ...
    (microsoft.public.dotnet.languages.csharp)
  • another prob
    ... thanks a lot those who helped with the switch statements. ... The 7th step states (in the constructor of the car class pass the car model ... I would be very grateful if you could please help me. ...
    (comp.lang.java.help)
  • Generics Serialization Exception
    ... Public Class Car { ... public NullableMeter; ... Car car = new Car; ... If I remove [XmlAttribute] then no problem it works. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Another simple problem
    ... > What if you wanted a method called newunder Foobar obj? ... > But then the Car() method call doesn't make sense. ... All I was proposing was changing the syntax of the constructor ...
    (comp.lang.java.programmer)
  • Re: difference
    ... == tests the equaliy of reference, and equals tests the equality of value. ... if (o instance of Car) { ...
    (comp.lang.java.help)