Razor Tutorial with Operators – Programming Example

In this chapter you will learn

  • How to use Operator in Razor Markup
  • Programming Example

How to use Operator in Razor Markup

Razor Markup supports many operators of C# and VB.Net. There is no special rule for using operators in razor markup. You can simply use operators same as you use in c# programming or vb programming. Most common operators that is used in Razor markup is follows.

1. Math Operators : It is + (Plus), (Minus) , * (Multiplication), / (Divide). It is used for mathematical calculation.

Example

  • Output

    Addition : 45 + 9 = 54
    Subtraction : 45 – 9 = 36
    Multiplication : 45 * 9 = 405
    Divide : 45 / 9 = 5
    2. Assignment Operator : It is =(equal to). It is used for assigning right side value to left side variable.

    Example
    int num = 55;

    3. Equality Operator : It is == (Equality). It returns true if left hand side and right hand side value are equal otherwise return false.

    Example

    Output

    Match Found : 12
    Match Found : 52
    4. Inequality Operator : It is != (Inequality). It returns true if both value are not equal.

    Example

    Output

    Returns True
    5. Comparison Operator : It is <, >, <=, => . It is used for comparing two integer or decimal values.

    Example

    Output

    5 is less than 10
    6. Concatenation Operator : It is + (Plus). It is used for joining two strings.

    Example

    Output

    This is Razor Tutorial. And you are learning at CompleteCsharpTutorial.com
    7. Increment and Decrement Operators : It is ++ or += and or -= . It is used for incrementing or decrementing integer value.

    Example

    Output

    Increment of 5 is : 6
    Decrement of 6 is : 5
    Increment of 5 is : 6
    Decrement of 6 is : 5
    8. Dot Operator : It is . (Dot). It is used to distinguish objects and their properties and methods.

    Example

    Output

    55
    Browser Name : chrome
    9. Parentheses : It is () . It is used to group expression and to pass parameters to methods.

    Example

    Output

    Addition is 15
    10. Bracket : It is [] . It is used for accessing value in arrays of collections.

    Example

    Output

    98
    11. Not Operator : It is ! (Not). It reverse true into false and false into true.

    Example

    Output

    However conditions are false still this message appears because you have used not operator and it reverse the condition.
    12. Logical Operator : It is && (AND) and || (OR). It is used to link conditions together and helps to make logic much better.&& – Returns true if all the specified conditions are true otherwise returns false.
    || – Returns true if one or all the conditions are true.

    Example

    Output

    Hello Steven, you have entered wrong password.

    Summary

    In this chapter you learned to use different types of operator with programming example that is used in razor markup. In the next chapter you will learn how to use Conditional Statements in Razor Markup.


    Leave a Reply

    Your email address will not be published. Required fields are marked *