S
Sudip_inn
Guest
i am getting compilation error when initialize list.
List<BrokerInfo> _bk = new List<BrokerInfo>()
_{
new BrokerInfo { Section="TestSec1",Lineitem="TestLi1" },
new BrokerInfo { Section = "TestSec2", Lineitem = "TestLi2" },
new BrokerInfo { Section="TestSec3",Lineitem="TestLi3" }
};
public class BrokerInfo
{
public string Section { get; set; }
public string Lineitem { get; set; }
}
my above code is not compiling and i am not being able to understand why i am getting error for above code. what to fix in above code ?
where as below code is same where i am using different class only which is not giving compilation error. see this code is working fine
List<CustomerorderModel> objOrder = new List<CustomerorderModel>()
{
new CustomerorderModel {ItemCode="MO12",ProductName="Mouse",Qty=1,Price=150.00,TotalAmount=150.00 },
new CustomerorderModel {ItemCode="CO11",ProductName="Cable",Qty=2,Price=250.00,TotalAmount=500.00 },
new CustomerorderModel {ItemCode="KO67",ProductName="KeyBoard",Qty=3,Price=500.00,TotalAmount=1500.00 },
new CustomerorderModel {ItemCode="PO55",ProductName="PenDrive",Qty=1,Price=200.00,TotalAmount=200.00 }
};
public class CustomerorderModel
{
[Display(Name = "Item Code")]
public string ItemCode { get; set; }
[Display(Name = "Product Name")]
public string ProductName { get; set; }
[Display(Name = "Quantity")]
public Int16 Qty { get; set; }
public double Price { get; set; }
[Display(Name = "Total Amount")]
public double TotalAmount { get; set; }
}
Continue reading...
List<BrokerInfo> _bk = new List<BrokerInfo>()
_{
new BrokerInfo { Section="TestSec1",Lineitem="TestLi1" },
new BrokerInfo { Section = "TestSec2", Lineitem = "TestLi2" },
new BrokerInfo { Section="TestSec3",Lineitem="TestLi3" }
};
public class BrokerInfo
{
public string Section { get; set; }
public string Lineitem { get; set; }
}
my above code is not compiling and i am not being able to understand why i am getting error for above code. what to fix in above code ?
where as below code is same where i am using different class only which is not giving compilation error. see this code is working fine
List<CustomerorderModel> objOrder = new List<CustomerorderModel>()
{
new CustomerorderModel {ItemCode="MO12",ProductName="Mouse",Qty=1,Price=150.00,TotalAmount=150.00 },
new CustomerorderModel {ItemCode="CO11",ProductName="Cable",Qty=2,Price=250.00,TotalAmount=500.00 },
new CustomerorderModel {ItemCode="KO67",ProductName="KeyBoard",Qty=3,Price=500.00,TotalAmount=1500.00 },
new CustomerorderModel {ItemCode="PO55",ProductName="PenDrive",Qty=1,Price=200.00,TotalAmount=200.00 }
};
public class CustomerorderModel
{
[Display(Name = "Item Code")]
public string ItemCode { get; set; }
[Display(Name = "Product Name")]
public string ProductName { get; set; }
[Display(Name = "Quantity")]
public Int16 Qty { get; set; }
public double Price { get; set; }
[Display(Name = "Total Amount")]
public double TotalAmount { get; set; }
}
Continue reading...