我只需要使用C#创建一个类 [英] I need to make a class using only C#
本文介绍了我只需要使用C#创建一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个具有属性名称和电子邮件集合的类条目,并且具有向本地文件系统保存和加载所有属性的能力
感谢OriginalGriff
i知道我需要一个Save()和Load()方法,这就是我需要帮助的部分
所以我再看了一下这就是我得到的东西
I need a class Entry with properties Name, and collection of Emails, and with the ability to
Save and Load all properties to/from local file system
Thanks OriginalGriff
i know that i need a Save() and Load() method thats the part i need help with
So i looked around a little more this is what i got
class Entry
{
public string Name { get; set; }
public IEnumerable<string> Emails { get; set; }
public void Save()
{
TextWriter tsw = new StreamWriter(@"C:\Emails.txt");
tsw.WriteLine(Name);
tsw.WriteLine();
foreach (string email in Emails)
{
tsw.WriteLine(email);
}
tsw.Close();
Process.Start(@"C:\Emails.txt");
}
public void Load()
{
TextReader trs = new StreamReader(@"C:\Emails.txt");
Console.WriteLine(trs.ReadToEnd());
trs.Close();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
dows任何人有任何sugestions或批评?
dows any one have any sugestions or critics?
推荐答案
public class Entry
{
public string Name { get; set; }
public IEnumerable<Email> Emails { get; set; }
public void Save()
{
}
public void Load()
{
}
}
这些方法留给读者练习。
The methods are left as an exercise for the reader.
这篇关于我只需要使用C#创建一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文