class Program
{
static void Main(string[] args)
{
string name = "Tony";
Person p = name;
Person p1 = new Person("Jack");
string name1 = (string)p1;
}
}
class Person
{
public string Name { get; set; }
public Person(string name)
{
this.Name = name;
}
//string到Person的隐式转换
public static implicit operator Person(string name)
{
return new Person(name);s
}
//Person到string的显示转换
public static explicit operator string(Person person)
{
return person.Name;
}
}