Create and Show Variables
Basic set variable and show
var Firstname = "Terry"
and show with @firstName
Output
Name: TerryNumbers and Dates
Output
Age: 27Birthday: 9/9/1999 12:00:00 AM
Birthday nicer using ToString("d"): 9/9/1999
Birthday as ISO ToString("yyyy-MM-dd"): 1999-09-09
Arrays (lists of things)
Output
Age: 27Birthday: 9/9/1999 12:00:00 AM
Birthday nicer using ToString("d"): 9/9/1999
Birthday as ISO ToString("yyyy-MM-dd"): 1999-09-09
Source Code of this file
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
@inherits Custom.Hybrid.Razor14 <!-- unimportant stuff, hidden --> @* 2dg: neue info section part *@ <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2>Create and Show Variables</h2> <h3>Basic set variable and show</h3> <p><code>var Firstname = "Terry"</code> and <code>show with @@firstName</code></p> </div> </div> @* 2dg: neue info section part *@ @{ var firstName = "Terry"; } Name: @firstName <h3>Numbers and Dates</h3> @{ var age = 27; var birthday = new DateTime(1999, 09, 09); } Age: @age <br> Birthday: @birthday <br> Birthday nicer using ToString("d"): @birthday.ToString("d") <br> Birthday as ISO ToString("yyyy-MM-dd"): @birthday.ToString("yyyy-MM-dd") <h3>Arrays (lists of things)</h3> @{ var dogs = new string[] { "hound", "dackel", "doggy" }; birthday = new DateTime(1999, 09, 09); } Age: @age <br> Birthday: @birthday <br> Birthday nicer using ToString("d"): @birthday.ToString("d") <br> Birthday as ISO ToString("yyyy-MM-dd"): @birthday.ToString("yyyy-MM-dd") @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })