using System;
using System.Collections.Generic;
using System.Collections ;
using System.Text;这是头
问题:新建了一个LIST<>
                        struct N
                           {
                                int index;
                                int value;
                                int weight;
                           }
                        List < N > goods = new List<N>(); 
然后输入goods.   
1  输入goods时,提示框中没有出现goods
2  goods.后边的提示没有出现该问题多次出现,麻烦高手另外指点,这类问题在其它窗口程序中怎么处理?
接着,向goods中输入数据
                        for (int i = 0; i < count; i++)
                        {
                                goods.add();
                                Console.WriteLine ( "输入元素" );
                                goods[i] = Console.ReadLine ();
                                goods[i].index = i;
                        }
出现多出红色提示,不知道为什么,请大家帮帮忙,谢谢了!

解决方案 »

  1.   

    上边的程序贴错了,应该为:
    for (int i = 0; i <count ; i++)
       {
          goods.add();
          Console.WriteLine ("输入元素");
          goods[i].value;
          goods[i].weight;
          goods[i].index = i;
       }
      

  2.   

    请帖出完整代码,单看这段程序,有以下错误:for (int i = 0; i < count; i++)
                            {
                                    goods.add();//方法Add的A应该大写,且必须接收一个N类型的参数
                                    Console.WriteLine ( "输入元素" );
                                    goods[i] = Console.ReadLine ();//Console.ReadLine()返回string类型,它怎么可能给goods[i]赋值?goods[i]是一个N类型的对象
                                    goods[i].index = i;
                            } 
      

  3.   

    感谢您这么快的回复!代码如下:
    using System;
    using System.Collections.Generic;
    using System.Collections ;
    using System.Text;
    namespace QiongJu
    {
            class Program
            {
                    static void Main(string[] args)
                    {
                            struct N
                            {
                                    int index;
                                    int value;
                                    int weight;
                            }
                            List < N > goods = new List<N>();      //所有的物品
                            List < N > T = new List<N>();     //存放所有可能的组合
                            static int m = 0;    //静态操作数组  便于操作
                            static int n = 0;
                            int bag = 20;   //袋子的承重量
                            static int count ;   //物品总数
                            Console .readline(count);
                            for (int i = 0; i < count; i++)
                            {
                                    goods.add();
                                    Console.WriteLine ( "输入元素" );
                                    goods[i] = Console.ReadLine ();
                                    goods[i].index = i;
                            }
                           
                            for ( int i = 0; i < count ;i++)
                            {
                                    s = goods[i].weight ;
                                    if ( bag >= s )
                                            T[m][n] = goods[i].weight ;  // 将第i件物品装入
                                                                                    n++;
                                    for (int k = i++; k < count ; k++)
                                    {
                                            for ( int j = k; j < count ; j++)
                                            {
                                                    s = s + goods[j].weight ;
                                                    if (bag > s)
                                                    {
                                                            T[m][n] = goods [j].weight ;
                                                            n++;
                                                    }
                                                    else
                                                    {
                                                            m++;
                                                            n = 0;
                                                            s = goods [i].weight ;
                                                            break ;
                                                    }
                                            }
                                    }
                            }
                    }
            }
    }
      

  4.   

    汗……看来你连最基本的C#语法及逻辑都还没熟悉……
    参考以下写法:        struct N
            {
                public int index;
                public int value;
                public int weight;
            } 
            static void Main(string[] args)
            {
                List<N> goods = new List<N>();
                int count = 3;
                for (int i = 0; i < count; i++)
                {
                    N n = new N();
                    Console.Write("请输入value:");
                    n.index = i;
                    n.value = int.Parse(Console.ReadLine());
                    Console.Write("请输入weight:");
                    n.weight = int.Parse(Console.ReadLine());
                    goods.Add(n);
                }            foreach (N n in goods)
                {
                    Console.WriteLine("index:{0},value:{1},weight:{2}", n.index, n.value, n.weight);
                }
            }
      

  5.   

    刚才修改如下:
    using System; 
    using System.Collections.Generic; 
    using System.Collections ; 
    using System.Text; 
    namespace QiongJu 

            class Program 
            { 
                    static void Main(string[] args) 
                    { 
                            struct N 
                            { 
                                    int index; 
                                    int value; 
                                    int weight; 
                            } 
                            List < N > goods = new List <N>();      //所有的物品 
                            List < N > T = new List <N>();    //存放所有可能的组合 
                            static int m = 0;    //静态操作数组  便于操作 
                            static int n = 0; 
                            int bag = 20;  //袋子的承重量 
                            static int count ;  //物品总数 
                            Console .readline(count); 
                            for (int i = 0; i < count; i++) 
                            {
                                    goods.add();
                                    Console.WriteLine ( "输入元素" );
                                    goods[i].value = Console.ReadLine ();
                                    goods[i].weight = Console .ReadLine (); 

                                    goods[i].index = i;
                            }
                          
                            for ( int i = 0; i < count ;i++) 
                            { 
                                    s = goods[i].weight ; 
                                    if ( bag >= s ) 
                                            T[m][n] = goods[i].weight ;  // 将第i件物品装入 
                                                                                    n++; 
                                    for (int k = i++; k < count ; k++) 
                                    { 
                                            for ( int j = k; j < count ; j++) 
                                            { 
                                                    s = s + goods[j].weight ; 
                                                    if (bag > s) 
                                                    { 
                                                            T[m][n] = goods [j].weight ; 
                                                            n++; 
                                                    } 
                                                    else 
                                                    { 
                                                            m++; 
                                                            n = 0; 
                                                            s = goods [i].weight ; 
                                                            break ; 
                                                    } 
                                            } 
                                    } 
                            } 
                    } 
            } 
    } 引用:
    system
    system.data
    system.xml
      

  6.   

    谢谢上边的回答,但是不能提示的问题还是没有解决    
    输入Console.也不能提示后边的,比如writeline   readline  等
      

  7.   

    goods[i].value = Console.ReadLine (); 
    goods[i].weight = Console .ReadLine (); ReadLine读入的是一个String,需要Parse成int
    如下:
    string s = Console.ReadLine();
    goods[i].value = int.Parse(s);
      

  8.   

    你说的不能提示后面的,应该是Intellisense出问题了,试试Ctrl+J,如果还不能出来,需要删除程序中那个.ncb文件,然后保证程序能编译通过,编译后它会自动update intellisense的。
      

  9.   

    先做好一個結構,再加到list當中去.你現在是先加,再創建好像有問題吧
      Goods.Add(goods)  //goods為創建好的結構