あにす #6609(2008/06/29 12:09 GMT) [ C# ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
using System; using System.IO; using System.Xml.Serialization; class Program { static void Main(string[] args) { string Path = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + "\\ShowPrice.xml"; XmlSerializer serializer = new XmlSerializer(typeof(Item)); //値セット Item item = new Item { Name = "りんご", Cost = 200 }; //書き込み using(StreamWriter sw = new StreamWriter(Path)) { serializer.Serialize(sw, item); } //ファイル内容表示 using(StreamReader sr = new StreamReader(Path)) { Console.WriteLine(sr.ReadToEnd()); } Console.ReadLine(); //読み込み,表示 using(StreamReader sr = new StreamReader(Path)) { item = (Item)(serializer.Deserialize(sr)); } Console.WriteLine("「{0}」は{1}円(税込み)", item.Name, item.Cost * 1.05); Console.ReadLine(); } } public class Item { public string Name { set; get; } public int Cost { set; get; } }
Rating0/0=0.00-0+
1 reply [ reply ]
あにす #6610(2008/06/29 12:18 GMT) Rating0/0=0.00
[ reply ]
あにす
#6609()
[
C#
]
Rating0/0=0.00
Rating0/0=0.00-0+
1 reply [ reply ]