مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

mehdi1359a

عضویت از 1394/02/03

استفاده از کلاسهای تو در تو

  • چهارشنبه 9 دی 1394
  • 01:07
تشکر میکنم

با سلام خدمت دوستان

از کلاس تو در توو استفاده می کنم خطا میده بصورت زیر:

 public class ItemsOfQuestions
    {
        public string item_title { get; set; }
        public Byte item_type { get; set; }
        public string item_image { get; set; }
        public Int16 item_grade { get; set;}
    }
    public class Questins_With_Items
    {
        
        public string question_title { get; set; }
        public List<ItemsOfQuestions> list_items { get; set; }
  
    }

بصورت زیر استفاده میکنم :


            List<ItemsOfQuestions> itemlist = new List<ItemsOfQuestions>();
            Questins_With_Items qwi = new Questins_With_Items();
            for (int i = 0; i < 5; i++)
            {
                ItemsOfQuestions ioq = new ItemsOfQuestions();
                ioq.item_title = "item"+i.ToString();
                ioq.item_type = 0;
                ioq.item_image = "";
                ioq.item_grade = (Int16)i;
                itemlist.Add(ioq);
       
            }            
            qwi.question_title = "سوال اول";
            qwi.list_items.Add(itemlist);

 

خطای:

Error    1    The best overloaded method match for 'System.Collections.Generic.List<graph1.ViewModels.ItemsOfQuestions>.Add(graph1.ViewModels.ItemsOfQuestions)' has some invalid arguments   

Error    2    Argument 1: cannot convert from 'System.Collections.Generic.List<graph1.ViewModels.ItemsOfQuestions>' to 'graph1.ViewModels.ItemsOfQuestions'   

علت چیه لطفا راهنمایی کنید ممنون .با تشکر

 

پاسخ های این پرسش

تعداد پاسخ ها : 2 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • چهارشنبه 9 دی 1394
  • 08:49

کد ها تون خوانا نیست

لطفا از کلید Code در ادیتور برای درج کد استفاده کنید

کاربر سایت

mehdi1359a

عضویت از 1394/02/03

  • چهارشنبه 9 دی 1394
  • 17:15

public class ItemsOfQuestions
    {
        public string item_title { get; set; }
        public Byte item_type { get; set; }
        public string item_image { get; set; }
        public Int16 item_grade { get; set;}
    }
    public class Questins_With_Items
    {
        
        public string question_title { get; set; }
        public List<ItemsOfQuestions> list_items { get; set; }
  
    }

بصورت زیر استفاده میکنم :


            List<ItemsOfQuestions> itemlist = new List<ItemsOfQuestions>();
            Questins_With_Items qwi = new Questins_With_Items();
            for (int i = 0; i < 5; i++)
            {
                ItemsOfQuestions ioq = new ItemsOfQuestions();
                ioq.item_title = "item"+i.ToString();
                ioq.item_type = 0;
                ioq.item_image = "";
                ioq.item_grade = (Int16)i;
                itemlist.Add(ioq);
       
            }            
            qwi.question_title = "سوال اول";
            qwi.list_items.Add(itemlist);

 

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)