How to access Properties of a class from a Generic Method - C#

前端 未结 5 595
-上瘾入骨i
-上瘾入骨i 2020-12-06 16:49

I have a three class which is having following properties

Class A
{
    public int CustID { get; set; }
    public string Name{ get; set; }
}

Class B
{
             


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 17:21

    dynamic

    should fix this issue, don't cast or go around in circles..

        List products = new List();
        foreach (dynamic prod in products)
        { 
            prod.ShopCategoryID = 1 ;  // give you access to props
        }
    

提交回复
热议问题