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[] {"," },
StringSplitOptions.RemoveEmptyEntries);
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(value);
}
}
private void button1_Click(object sender, EventArgs e)
{
MyType mt = (MyType)"wjs, 30";
Console.WriteLine(mt)
}
--
William Stacey [MVP]
"John Cotsell" <jo**********@formicary.net> wrote in message
news:u5**************@TK2MSFTNGP14.phx.gbl...
| Basically I have a class called Dog and when using the objectdatasource 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*********@hotmail.com
|
| cheers John
|
|
|