Skip to main content
Home  › ... 2sxc Apps

Basic Tutorials

Tutorial Home
#1 Variables

Basic set variable and show

var Firstname = "Terry" and show with @firstName

Name: Terry

@{
  var firstName = "Terry";
}

Name: @firstName

Numbers and Dates

Age: 27
Birthday: 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

@{
  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")

Arrays (lists of things)

Age: 27
Birthday: 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

@{
  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")
#1 Variables

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 -->

<div class="row">
  <div class="col-lg-7">
    <h2>Create and Show Variables</h2>
  </div>
  @Html.Partial("../shared/_DefaultInfoSection.cshtml")
</div>

<h3>Basic set variable and show</h3>
<p><code>var Firstname = "Terry"</code> and <code>show with @@firstName</code></p>

@{
  var firstName = "Terry";
}

Name: @firstName





<hr>
<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")




<hr>
<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")



<!-- unimportant stuff, hidden -->