Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > supply final static value

Reply
Thread Tools

supply final static value

 
 
Dan
Guest
Posts: n/a
 
      03-11-2005
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


 
Reply With Quote
 
 
 
 
Lionel LASKE
Guest
Posts: n/a
 
      03-11-2005

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" <(E-Mail Removed)-tuebingen.de> a écrit dans le message de news:
d0s64s$urm$(E-Mail Removed)-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
>
>



 
Reply With Quote
 
 
 
 
Manohar Kamath
Guest
Posts: n/a
 
      03-11-2005
You could do something like:

public static string redColor = "Red";

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


"Dan" <(E-Mail Removed)-tuebingen.de> wrote in message
news:d0s64s$urm$(E-Mail Removed)-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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any sense in using private static final for non-static classes? Ricardo Palomares Martinez Java 2 04-28-2007 10:45 PM
Word open as Final, not Final Showing Markup Karl Engel Computer Support 4 12-19-2006 04:20 AM
Non-final class at compile-time, final at runtime pietdejong@gmail.com Java 5 11-17-2006 12:30 PM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
RCA 030 Camera Power supply RCA CPS02 Power Supply nick Digital Photography 0 01-22-2004 10:27 PM



Advertisments