Reputation: 379
I am not sure I am asking this question properly and have had trouble searching for what I need in this case. I have two classes. One consists of three items that I will assign.
namespace Common.PriceFeed
{
public class SurchargeSKUList
{
public string WebSKUID { get; set; }
public decimal AdditionalPrice { get; set; }
public string Currency { get; set; }
}
}
The other class is a list containing the items from the above class.
namespace Common.PriceFeed
{
public class BaseSurcharge
{
public List<SurchargeSKUList> SKUList { get; set; }
}
}
My problem is, then I try to use BaseSurcharge, I get errors like I am using as type as a variable or that I "cannot implicitly convert type..." My .net code is below.
Thank you.
if (BaseSurcharges.Rows.Count > 0)
{
foreach (DataRow row in BaseSurcharges.Rows)
{
SurchargeSKUList newSKUList = new SurchargeSKUList();
newSKUList.WebSKUID = row["WebSKUID"].ToString();
newSKUList.AdditionalPrice = Convert.ToDecimal(row["AdditionalPrice"]);
newSKUList.Currency = row["Currency"].ToString();
BaseSurcharge newSurcharge = new BaseSurcharge();
newSurcharge.SKUList = List<SurchargeSKUList>newSKUList;
//BaseSurcharge List<SurchargeSKUList> newSurcharge = new BaseSurcharge
//BaseSurcharge newSurcharge = new BaseSurcharge();
//newSurcharge.SKUList = newSKUList;
}
}
Upvotes: 1
Views: 14386
Reputation: 27633
newSurcharge.SKUList = List<SurchargeSKUList>newSKUList;
should be changed to:
newSurcharge.SKUList = new List<SurchargeSKUList>();
newSurcharge.SKUList.Add(newSKUList);
I didn't check this out on Visual Studio. So it might have some syntax errors.
But better yet - BaseSurcharge
should have SKUList = new List<SurchargeSKUList>();
in its constructor.
Upvotes: 9