这些标签有什么用?< employee> < / employee>,它给出了错误 [英] What is the use of these tags <employee> </employee>, it is giving error
问题描述
public List<Employee><employee> GetEmployees()
{
List<Employee><employee> employees = new List<Employee><employee>();
Employee emp = new Employee();
emp.FirstName = "johnson";
emp.LastName = " fernandes";
emp.Salary = 14000;
employees.Add(emp);</employee>
当我使用这些标签时会发出错误
when I'm using these tags it's giving an error
<employee>
</employee>
我尝试过:
我正在尝试制作一个列表,因为我正在学习MVC
如果我能解决错误在使用Visual Studio 2012时,这部分代码来自7天内学习MVC。
What I have tried:
I'm trying to make a list as I'm learning MVC
how to fix the error if I'm using Visual Studio 2012,this part of code is from learn MVC in 7 days.
推荐答案
它不是标签 - 它是使用泛型类的C#语法。
您可以阅读
It's not a tag - it's the C# syntax for using a generic class.
You can read
List<Employee> employees = new List<Employee>();
作为创建一个名为的变量员工
其中包含一个Employee类实例列表,并为其分配一个新的Employee实例列表
当您创建一个Generic集合(其中List只是一个示例)时,您需要准确指定它可以包含哪些类(或基类)作为泛型是强类型的:除了正确的类的实例之外,你不能添加任何东西。因此,如果您声明一个双打列表:
As "Create a variable called employees
which contains a List of Employee class instances, and assign a new empty List of Employee instance to it"
When you create a Generic collection (of which List is just one example) you need to specify exactly what class (or base class) it can contain as Generics are strongly typed: you can't add anything except instances of the right class to them. So if you declare a list of doubles:
List<double> myList = new List<double>();</double></double>
您可以添加双值,但不能添加整数:
You can add double values, but not integers:
int i = 666;
double d = 666.666;
myList.Add(d); // Fine.
myList.Add(i); // Compiler error.
与HTML不同,C#不需要你关闭类型说明符 - 这只是HTML和XML的一个特性,而不是C#源代码。
unlike HTML, C# does not need to you "close" the type specifier - that is a feature of HTML and XML only, not of C# source code.
这些标签有什么用?< employee> < / employee>
What is the use of these tags <employee> </employee>
这些标签是XML标签,您尝试在c#程序中混合它们。问题是XML标签在C#语言中是未知的,因此它们不会混合在一起。
你试图做的事情非常模糊。
These tags are XML tags and you try to mix them in a c# program. Problem is that XML tags are unknown from C# language and so they don't mix together.
What you try to do is pretty obscure.
这篇关于这些标签有什么用?< employee> < / employee>,它给出了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!