本文整理汇总了C#中Person.SetId方法的典型用法代码示例。如果您正苦于以下问题:C# Person.SetId方法的具体用法?C# Person.SetId怎么用?C# Person.SetId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.SetId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Person person = new Person();
person.SetId(1);
person.FirstName = "Luis Felipe";
person.LastName = "Oliveira";
//Creating the file and Serializing
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
StreamWriter sr = new StreamWriter("Person.xml");
xmlSerializer.Serialize(sr, person);
}
示例2: Main
static void Main(string[] args)
{
Person person = new Person();
person.SetId(1);
person.FirstName = "Luis Felipe";
person.LastName = "Oliveira";
IFormatter formatter = new BinaryFormatter();
//Creating the File and Serializing
Stream sr = new FileStream("Person.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(sr, person);
sr.Close();
}
示例3: Main
static void Main(string[] args)
{
Person person = new Person();
person.SetId(1);
person.FirstName = "Joe";
person.LastName = "Smith";
Stream stream = new FileStream("Person.json", FileMode.Create);
//Use the DataContractJsonSerializer to serialize an object to JSON. It's in the System.Runtime.Serialization.Json namespace
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Person));
ser.WriteObject(stream, person);
stream.Close();
//To read the JSON back to the object you need to use the ReadObject method of the DataContractJsonSerializer
}