supply final static value

Discussion in 'ASP .Net Web Services' started by Dan, Mar 11, 2005.

  1. Dan

    Dan Guest

    hi ng,

    is it possible in dotnet to restrict a value for a variable.
    i remember that there is something like that in delphi.

    my problem:
    i have a bussiness object that has a string variable which can only be
    set to some well defined values.
    Like:

    string color="red" (or "white" or "black")


    and the webservice should define the strings red, white, black.

    thanks for your help,
    dan
     
    Dan, Mar 11, 2005
    #1
    1. Advertising

  2. Dan

    Lionel LASKE Guest

    I'm afraid you can't restrict values in .NET except if you develop your own
    class "StringRestricted" and test value on each set call to ensure that your
    class can't have an illegal value.
    Alternatively, why not using an enum like this:

    public enum MyEnum
    {
    red,
    white,
    black
    }

    MyEnum e = red;
    Debug.WriteLine(e.ToString()); // "red"
    e = (MyEnum) TypeDescriptor.GetConverter(e).ConvertFrom("black"); // black


    Lionel.


    My guess is that you can use an enum an do
    "Dan" <-tuebingen.de> a écrit dans le message de news:
    d0s64s$urm$-tuebingen.de...
    > hi ng,
    >
    > is it possible in dotnet to restrict a value for a variable.
    > i remember that there is something like that in delphi.
    >
    > my problem:
    > i have a bussiness object that has a string variable which can only be set
    > to some well defined values.
    > Like:
    >
    > string color="red" (or "white" or "black")
    >
    >
    > and the webservice should define the strings red, white, black.
    >
    > thanks for your help,
    > dan
    >
    >
     
    Lionel LASKE, Mar 11, 2005
    #2
    1. Advertising

  3. You could do something like:

    public static string redColor = "Red";

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Dan" <-tuebingen.de> wrote in message
    news:d0s64s$urm$-tuebingen.de...
    > hi ng,
    >
    > is it possible in dotnet to restrict a value for a variable.
    > i remember that there is something like that in delphi.
    >
    > my problem:
    > i have a bussiness object that has a string variable which can only be
    > set to some well defined values.
    > Like:
    >
    > string color="red" (or "white" or "black")
    >
    >
    > and the webservice should define the strings red, white, black.
    >
    > thanks for your help,
    > dan
    >
    >
     
    Manohar Kamath, Mar 11, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Todd
    Replies:
    2
    Views:
    469
    Joe Smith
    Jul 22, 2004
  2. JFCM
    Replies:
    4
    Views:
    5,740
  3. Replies:
    5
    Views:
    520
    Chris Uppal
    Nov 17, 2006
  4. Ricardo Palomares Martinez
    Replies:
    2
    Views:
    378
    david.karr
    Apr 28, 2007
  5. Replies:
    0
    Views:
    373
Loading...

Share This Page