0

我得到了错误var ts = System.Threading.ThreadStart(delegate()(红线淹没在下面System.Threading.ThreadStart)。问题是什么?

using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        public Program()
        {
            int[] iArray = new int[3];
            iArray[0] = 2;
            iArray[1] = 1;
            iArray[2] = 5;
            var ts = System.Threading.ThreadStart(delegate()
            {
                foreach (int i in iArray)
                    Foo(i);
            });
        }

        public void Foo(int i)
        {
            Console.WriteLine(i + ",");
        }

        public static void Main(String[] args)
        {
            Program p = new Program();
        }
    }
}
4

1 回答 1

1

您缺少一个new

var ts = new System.Threading.ThreadStart(delegate()
         {
             foreach (int i in iArray)
                 Foo(i);
         });

顺便提一句:

您不必ThreadStart为其命名空间添加前缀System.Threading,因为您已经using在 *.cs 文件的顶部声明了它。

于 2012-12-16T12:53:32.363 回答