【发布时间】:2016-02-09 14:43:23
【问题描述】:
'Employee' 是一个“命名空间”,但用作“类型”。我似乎无法纠正这 4 个错误。帮助任何人?第 12 行和第 27 行。我在 2 个错误行上做了解释。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Employee
{
class Program
{
static void Main(string[] args)
{
Employee firstEmployee = new Employee(); **(2 errors on line for Employee)**
ApplicationUtilities.DisplayApplicationInformation(); //display the header for the application
ApplicationUtilities.DisplayDivider("Start Program"); //Show heading that the program has started
ApplicationUtilities.DisplayDivider("Prompt for employee information and create first employee"); //Heading that shows we are ready to input first employee information
firstEmployee.firstName = InputUtilities.getStringInputValue("First Name"); //Get first name input from the user
firstEmployee.lastName = InputUtilities.getStringInputValue("Last Name");//Get last name input from the user
firstEmployee.gender = InputUtilities.getCharInputValue("Gender");//Get gender input from the user
firstEmployee.dependents = InputUtilities.getIntegerInputValue("# Dependents");//Get dependent input from the user
firstEmployee.annualSalary = InputUtilities.getDoubleInputValue("Annual Salary");//Get annual salary input from the user
Console.WriteLine("");
Console.Write(firstEmployee.ToString());
ApplicationUtilities.PauseExecution();
Employee secondEmployee = new Employee("First Name", "Last Name", 'F', 3, 52000); ////declare an instance of second employee object with overloaded constructor called **(2 errors on this line for - Employee)**
Console.Write(secondEmployee.ToString());
ApplicationUtilities.TerminateApplication();
}
}
}
【问题讨论】:
-
你有一个命名空间和一个同名的类 - Employee。这是不允许的。
-
@JamieMeyer 不正确。只需要使用完全限定名称(不推荐)
-
感谢您的更正,米奇。今天学到了新东西。我确信有一个最佳实践建议不要这样做,以避免混淆编译器。
-
@bbravo55 顺便说一句,CA1724: Type Names Should Not Match Namespaces
标签: c#