Environment: Visual Studio 2012, .NET 4 Framework, ASP.NET Web Application (C #)
I would like to know the best, most appropriate approach to achieve the limitation of incoming arguments (of any type ... int, string, etc.) to a predefined set of desired values. I would like to know the best way accepted in the industry.
(the following code does not work - it's just to better illustrate the question)
Suppose I have a utility class:
public class Utilities
{
public string ConvertFromBytes(int intNumBytes, string strOutputUnit)
{
switch(strOutputUnit.ToUpper())
{
case "KB":
break;
case "MB":
break;
case "GB":
break;
}
}
}
Then on one of my pages I have something like this:
Utilities ut = new Utilities();
strConvertedFilesize = ut.ConvertFromBytes(1024,
, , , , - , "KB", "MB" "GB" strOutputUnit? () , intellisense ?
: JaredPar :
public class Utilities
{
public enum OutputUnit {
KB,
MB,
GB
}
public string ConvertFromBytes(int intNumBytes, OutputUnit ou)
{
switch (ou)
{
case OutputUnit.KB:
break;
case OutputUnit.MB:
break;
case OutputUnit.GB:
break;
default:
break;
}
return "";
}
}
:
Utilities ut = new Utilities();
string strConvertedFilesize = ut.ConvertFromBytes(1024, Utilities.OutputUnit.MB);
? "Utilities.OutputUnit". ... , , ?
BTW . JaredPar , . , , .