本文介绍了将数据存储到与类列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下类:
public class EmailData
{
public string FirstName{ set; get; }
public string LastName { set; get; }
public string Location{ set; get; }
}
然后我做了以下内容,但不能正常工作:
I then did the following but was not working properly:
List<EmailData> lstemail = new List<EmailData>();
lstemail.Add("JOhn","Smith","Los Angeles");
我得到一个消息,说不准过载方法需要3个参数。
I get a message that says no overload for method takes 3 arguments.
推荐答案
如果您希望实例,并添加在同一行,你必须做这样的事情:
If you want to instantiate and add in the same line, you'd have to do something like this:
lstemail.Add(new EmailData { FirstName = "JOhn", LastName = "Smith", Location = "Los Angeles" });
或以前只是实例化对象,并直接将其添加:
or just instantiate the object prior, and add it directly in:
EmailData data = new EmailData();
data.FirstName = "JOhn";
data.LastName = "Smith";
data.Location = "Los Angeles"
lstemail.Add(data);
这篇关于将数据存储到与类列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!