Click here to Skip to main content
15,891,692 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
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
XML
<employee>
XML
</employee>


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.
Posted
Updated 25-Apr-16 23:41pm
v2
Comments
Sergey Alexandrovich Kryukov 26-Apr-16 4:07am    
Tag?! Aren't you confusing C#, .NET and HTML? :-)
And why writing anything at all without reading on the basics of programming? Don't waste your time, learn.
The "question" makes no sense at all.
Don't even try to fix it: you are not ready. First learn the basics and come back.
—SA
Coder.Shekher 26-Apr-16 4:23am    
I'm reading the code project's article "learn Asp.net mvc in 7 days".I have came across this part of code over there.So please can you tell me how to fix it.If this is not the correct way of learning MVC ,can you suggest me from where I could learn it.
Sergey Alexandrovich Kryukov 26-Apr-16 4:42am    
There is nothing to fix, only your understanding. I don't need to know what you are reading. Please, stop writing gibberish. First, read something. Learning ASP.NET has it's prerequisites: knowing 2 + 2 of programming. You don't have it yet.
—SA
Passion4Code 26-Apr-16 9:51am    
Very true Sir

It's not a tag - it's the C# syntax for using a generic class.
You can read
C#
List<Employee> employees = new List<Employee>();
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:
C#
List<double> myList = new List<double>();</double></double>
You can add double values, but not integers:
C#
int i = 666;
double d = 666.666;
myList.Add(d);  // Fine.
myList.Add(i);  // Compiler error.

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.
 
Share this answer
 
Quote:
What is the use of these tags <employee> </employee>
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900