Well, you have to know the type first. Once you know the type, you can call
the types Parse() method. You could also implement explicit or implicit
converstion operators from String type.
public class MyType
{
public string Name;
public int Age;
public MyType()
{
}
public static MyType Parse(string value)
{
string[] sa = value.Split(new string[] {"," },
StringSplitOpti ons.RemoveEmpty Entries);
MyType mt = new MyType();
mt.Name = sa[0];
mt.Age = int.Parse(sa[1]);
return mt;
}
public override string ToString()
{
return Name + "," + Age.ToString();
}
public static explicit operator MyType(string value)
{
return MyType.Parse(va lue);
}
}
private void button1_Click(o bject sender, EventArgs e)
{
MyType mt = (MyType)"wjs, 30";
Console.WriteLi ne(mt)
}
--
William Stacey [MVP]
"John Cotsell" <jo**********@f ormicary.net> wrote in message
news:u5******** ******@TK2MSFTN GP14.phx.gbl...
| Basically I have a class called Dog and when using the objectdatasourc e I
| can use a string parameter to pass into the selectmethod. so I pass in a
| string = 'Dog' now once in the selectmethod I need to convert that string
| into and object of type Dog...I hope this makes sense. Do anyone know how
to
| do this???? i guess I need a similar method to Eval in javascript.
|
| Please need urgent so could replies also go to
jo*********@hot mail.com
|
| cheers John
|
|
|