In this chapter you will learn
- How to use Collection inside Razor Syntax
- Programming Example
How to use Collection inside Razor Syntax
A collection is a group of objects of the same type. There are mainly two common collections are used in razor, Array and Dictionary. You have learned Array in previous chapter so we will focus on Dictionary in this chapter.
A dictionary is a collection of key/value pairs and you can use it in programming as follow:
<meta charset="utf-8" />
var result = new Dictionary<string, int>();
<h3>Results of the students are:</h3>
<h3>Jack : @result["Jack"]</h3>
<h3>Steven : @result["Steven"]</h3>
<h3>Clark : @result["Clark"]</h3>
Jack : 75
Steven : 80
Clark : 95
In this chapter you learned to use Dictionary in razor syntax. You are free to use any types of collection in razor syntax. In the next chapter you will learn creating Methods with parameter in Razor Syntax.