本文整理汇总了C#中Person.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Person.ToString方法的具体用法?C# Person.ToString怎么用?C# Person.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
var target = new Person
{
GivenNames = "John",
FamilyName = "Smith"
};
Debug.WriteLine(target.ToString());
Assert.AreEqual("{T: \"Person\", GivenNames: \"John\", FamilyName: \"Smith\"}", target.ToString());
}
示例2: Main
static void Main()
{
Person ivan = new Person("Ivan", 23, "[email protected]");
Console.WriteLine(ivan.ToString());
Person gosho = new Person("Gosho", 25);
Console.WriteLine(gosho.ToString());
}
示例3: Main
static void Main(string[] args)
{
Person gosho = new Person("Gosho", 20);
Person pesho = new Person("Pesho", 20, "[email protected]");
Console.WriteLine(gosho.ToString());
Console.WriteLine(pesho.ToString());
}
示例4: Main
static void Main()
{
Person tom = new Person("Tom");
Console.WriteLine(tom.ToString());
Person josh = new Person("Josh", 20);
Console.WriteLine(josh.ToString());
}
示例5: inheritance_example
public inheritance_example()
{
//casting
object foo = (object)10;//casting 10 as an object and storing it in foo. We are not changing the value.
int bar = (int)foo;
Console.WriteLine("The value of bar is: "+bar);
Console.WriteLine((new Person("Jake", "Coddaire")));//prints helloworld.person.
Person jake = new Person("Jake", "Coddaire");
object lar = jake;//no difference. You went up to the parent. Value does not change. Stored in a different way.
Person james = (Person)lar;//we need to tell the compiler that this is a person object.
Console.WriteLine(jake.ToString());//this doesn't give me anything useful. We can OVERRIDE it.
//after overriding it in the PERSON class it works as we like it to.
Console.WriteLine(james.ToString());
//the lesson continues on some custom software.
Person matt = new Employee("Matt", "Gerber", "Boss");
Console.WriteLine(matt.ToString());
Console.WriteLine(matt.sayHello("Katie"));
//abstract classes are used exclusively with inheritance. More on the next lesson.
}
示例6: Main
static void Main()
{
Person firstPerson = new Person("pesho", 17);
Person secondPerson = new Person("gosho");
Console.WriteLine(firstPerson.ToString());
Console.WriteLine(secondPerson.ToString());
}
示例7: Main
static void Main(string[] args)
{
var p = new Person("Ivan", 70, "[email protected]");
var pp = new Person("Ivan", 33, null);
Console.WriteLine(p.ToString());
Console.WriteLine(pp.ToString());
}
示例8: Main
public static void Main()
{
Person pesho = new Person("Pesho", 25,"[email protected]");
pesho.Email = null;
Console.WriteLine(pesho.ToString());
}
示例9: Main
static void Main()
{
Person person1 = new Person("Ivan", 66);
Console.WriteLine(person1.ToString());
Person person2 = new Person("Petko");
Console.WriteLine(person2.ToString());
}
示例10: Main
static void Main(string[] args)
{
//PhoneCustomer myCustomer = new PhoneCustomer();
//PhoneCustomerStruct myCustomer2 = new PhoneCustomerStruct();
////if (myCustomer2 is ValueType)
////{
//// Console.WriteLine("ValueType:");
////}
////else
////{
//// Console.WriteLine("not ValueType:");
////}
//Console.WriteLine((myCustomer2 is ValueType) ? "ValueType":"NotValType");
Person person1 = new Person { Name = "Petya" , Age = 11};
Person person2 = new Person { Name = "Petya", Age = 22 };
Person person3 = new Person { Name = "Petya", Age = 11 };
Person person4 = person1;
Person person5 = null;
Person person6 = null;
Console.WriteLine(person1.Equals(person2));
Console.WriteLine(person1.Equals(person3));
Console.WriteLine(person4.Equals(person1));
Console.WriteLine("hash:"+person1.GetHashCode());
Console.WriteLine(person2.ToString());
Console.WriteLine(person1==person3);
Console.WriteLine(person1 != person2);
Console.WriteLine(person5 != person6);
}
示例11: TestConstructorWithId
public void TestConstructorWithId()
{
var person = new Person(1, "jane", "roe");
Assert.AreEqual("jane roe", person.ToString());
Assert.AreEqual("jane", person.FirstName);
Assert.AreEqual("roe", person.LastName);
Assert.AreEqual(1, person.Id);
}
示例12: Main
public static void Main()
{
Console.WriteLine("**** Fun with System.Object ****\n");
Person p1 = new Person();
Console.WriteLine("ToString: {0}", p1.ToString());
Console.WriteLine("ToString: {0}", p1.GetHashCode());
Console.WriteLine("ToString: {0}", p1.GetType());
}
示例13: Main
static void Main(string[] args)
{
Person pesho = new Person("Pesho", 73);
Console.WriteLine(pesho.ToString());
Console.WriteLine();
Person ivo = new Person("Ivo");
Console.WriteLine(ivo.ToString());
}
示例14: TestMethod1
public void TestMethod1()
{
Person anastas = new Person();
anastas.name = "Anastas Ivanov";
//"Name: {0} \n\rAge is not specified.", name
StringBuilder a = new StringBuilder();
a.AppendFormat("Name: {0}", anastas.name);
string output = a.ToString();
Assert.AreEqual(1, anastas.ToString());
}
示例15: Main
public static void Main()
{
Console.WriteLine("Enter name");
string name = Console.ReadLine();
Person person = new Person(name);
Console.WriteLine(person.ToString());
Console.WriteLine("Enter age");
byte age = byte.Parse(Console.ReadLine());
Person otherPerson = new Person(name, age);
Console.WriteLine(otherPerson.ToString());
}