Thursday, September 13, 2012

Operators inMVC


Operator

Description

Example

.

Dot. Used to distinguish objects and theirproperties and methods.

var myUrl = Request.Url;var count =Request["Count"].AsInt();

()

Parentheses. Used to group expressions and topass parameters to methods.

@(3 + 7)@Request.MapPath(Request.FilePath);

[]

Brackets. Used for accessing values in arrays orcollections.

var income =Request["AnnualIncome"];

=

Assignment. Assigns the value on the right side of a statement to the object on the left side. (Noticethe distinction between the = operator and the == operator.)

var age = 17;

!

Not. Reverses a true value to false and viceversa. Typically used as a shorthand way to testfor false (that is, for not true ).

bool taskCompleted = false;// Processing.if(!taskCompleted) {// Continue processing}

==

Equality. Returns true if the values are equal.

var myNum = 15;if (myNum == 15) {// Do something.}

!=

Inequality. Returns true if the values are notequal.

var theNum = 13;if (theNum != 15) {// Do something.}

<

>


<=

>=

Less-than,greater-than,less-than-or-equal, andgreater-than-or-equal.

if (2 < 3) {// Do something.} var currentCount = 12; if(currentCount >= 12) {// Do something.}

+

Math operators used in numerical expressions.

@(5 + 13)@{ var netWorth = 150000; }@{ var newTotal = netWorth * 2; }

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...