【发布时间】:2020-04-16 02:31:59
【问题描述】:
当我尝试在 Visual Studio 中构建代码时,它显示错误为
- 'Employee' 是一种类型,在给定的上下文中无效。
- 严重性代码描述项目文件行
错误 CS0246 找不到类型或命名空间名称“C1”(您是
缺少 using 指令或程序集引用?)
SecondC C:\Users\ypoint\source\repos\SecondC\SecondC\Program.cs 36
我是 C# 新手,请帮我解决这个问题。
using System;
public struct Emplyoee
{
private int _Id;
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
public int ID
{
get { return this._Id; }
set { this._Id = value; }
}
public Emplyoee(int Id, string Name)
{
this._Id = Id;
this._name = Name;
}
public void PrintDetails()
{
Console.WriteLine("Id={0} && Name={1}", this._Id, this._name);
}
}
public class Program
{
public static void Main()
{
Emplyoee C1 = new Emplyoee(101, "Sudharshan");
C1.PrintDetails();
}
}
【问题讨论】:
-
我尝试过使用 vs 2017 c# 3.0,它适用于我并输出 Id=101 && Name=Sudharshan,我认为您的问题来源不同
-
添加您项目的命名空间块以获得此代码并尝试。
标签: .net visual-studio-2017 c#-3.0