Sam,
If you want to have some sort of exception handling, you would have to
define a static method somewhere and then call that in the call to the other
constructor, like so:
private static int ValidateStringConstructorArgument(string s)
{
// Do something here, but return an int to pass to the overload of C
}
public C(string s) : this(ValidateStringConstructorArgument(s))
{}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Sam Sungshik Kong" <ss*@chol.nospam.net> wrote in message
news:Ox**************@TK2MSFTNGP15.phx.gbl...
Hello!
Here's a simple class.
class C
{
public int Num;
public C(int i)
{
Num = i;
}
public C(string s): this(int.Parse(s))
{
}
}
When I create an object..
C o = new C("1"); //this is ok.
C o = new C("a"); //this causes an error, of course.
I want to have some exception handling mechanism for the argument
validation
in the class.
What's the common practice for such a situation?
Thanks.
Sam