C# 错误CS0116:命名空间不能直接包含字段或方法等成员-使用记事本手写编码
使用foreach在第16行获取错误。我的教授发电子邮件的速度不够快,截止日期还有几个小时!我想我遗漏了一张清单什么的。我认为双精度后的d是不正确的。任何帮助都是欲望C# 错误CS0116:命名空间不能直接包含字段或方法等成员-使用记事本手写编码,c#,C#,使用foreach在第16行获取错误。我的教授发电子邮件的速度不够快,截止日期还有几个小时!我想我遗漏了一张清单什么的。我认为双精度后的d是不正确的。任何帮助都是欲望 using System; using System.Windows.Forms; using System.Collections.Generic; public class Starbucks { public static void Main() { double[] x = {4.2, 5.7, 3.6, 9.1,
using System;
using System.Windows.Forms;
using System.Collections.Generic;
public class Starbucks
{
public static void Main()
{
double[] x = {4.2, 5.7, 3.6, 9.1, 2.7, 8.4 };
}
}
static void MyGenerics(double x)
{
foreach (double d in x)
{
MessageBox.Show(x);
}
}
这是因为您在类
Starbucks
之外定义了MyGenerics()
方法。把它移到教室里。错误消息正告诉我们同样的事情。您的代码应该如下所示
using System;
using System.Windows.Forms;
using System.Collections.Generic;
public class Starbucks
{
public static void Main()
{
double[] x = {4.2, 5.7, 3.6, 9.1, 2.7, 8.4 };
MyGenerics(x);
}
static void MyGenerics(double[] xx)
{
foreach (double d in xx)
{
MessageBox.Show(d);
}
}
}
此问题可能是由于压痕不良造成的。例如:
using System;
namespace Interrogacion_1.Model
{
interface IClass
{
public string Name { get; set; }
}
{
Console.WriteLine("HELLO WORLD"); #here error cs0116
}
}
正确的方法是:
using System;
namespace Interrogacion_1.Model
{
interface IClass
{
public string Name { get; set; }
public void Imprimir()
{
Console.WriteLine("HELLO WORLD");
}
}
}
非常感谢你。这是课堂上唯一让我困惑的话题;