Use Array inside Razor Syntax

In this chapter you will learn
  • How to use array inside Razor Syntax
  • Single-Dimensional Array and Multi-Dimensional Array
  • Programming Example
You can use single-dimensional array and multi-dimensional array inside razor syntax as follow

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        @{
            //Single Dimensional Array
            <h3>Single Dimensional Array</h3>
            int[] arr={1,3,5,7,11,13,17,19};
            foreach(int x in arr)
            {
                <span>@x, </span>
            }
 
            //Multi Dimensional Array
            <h3>Multi Dimensional Array</h3>
            string[,] letter=new string[3,2] {{"a","b"},{"c","d"},{"e","f"}};
            for(int i=0; i<3; i++)
            {
                for(int j=0; j<2; j++)
                {
                    <span>@letter[i,j], </span>
                }
                <br />
            }
        }
    </body>
</html>
  Output
Single Dimensional Array 1, 3, 5, 7, 11, 13, 17, 19, Multi Dimensional Array a, b, c, d, e, f,

Summary

In this chapter you learned to use array in razor syntax. In the next chapter you will learn to use Collection inside Razor Syntax.

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.