【发布时间】:2013-09-01 08:40:41
【问题描述】:
我有一个类,其中包含一些不同数据类型的项目。我想为每个项目设置值并将其从控制器发送到视图,并在文本框中查看数据。
是否可以循环遍历类中的这些对象,检查其数据类型,然后为每个对象赋值?
这是我正在尝试完成的伪代码示例
foreach item in class ItemProduction
{
if data type == string
value of item = " " ;
if data type == int
value of item = 0 ;
if data type == DAte
value of item = date of today ;
}
这是我的类定义和其中的对象。
public class ItemProduction : Common, IDataErrorInfo, INotifyPropertyChanged
{
public string Main{ get; set; }
public DateTime itemDate { get; set; }
public string ItemType{ get; set; }
public string productionId{ get; set; }
public int Quantity { get; set; }
public string Status { get; set; }
}
【问题讨论】:
-
你只是想初始化
ItemProduction的List吗? -
@Bhushan Firake 我想为每个项目设置值,但首先我想检查每个项目的数据类型
-
@user2269364 请检查我的回答。
标签: c# asp.net asp.net-mvc-3 class foreach