Asp.net| tutorial Mike the old cat
From: The ideal of an old cat
This tutorial is written in C # and ASP.net programming tutorials, what are the deficiencies please point out, or in the old cat ideal blog message.
This is a brief introduction to the operator
1. Arithmetic operator
Arithmetic operators include addition (+), subtraction (-), multiplication (*), addition (/), and remainder (%). The subtraction operator is also applied to enumeration types, string types, and delegate types, in addition to the addition and subtraction of integers and real numbers, which are implemented by operator redirection.
String mf1= "Mike";
String mf2= "Cat";
String mf3=mf1+mf2;//mf3= "Mikecat"
Using System;
Enum Weekday
{
Sunday,monday,tuesday,wednesday,thursday,friday,saturday
};
Class Mikecat
{
static void Main ()
{
Weekday mf1=weekday.sunday;
Weekday mf2=mf1+3;
Console.WriteLine ("Mf1={0},mf2={1}", MF1,MF2);
}
}//Results: Mf1=sunday,mf2=wednesday
2. Assignment operator
Assignment is to assign a new value to a variable. C # is divided into simple assignment and compound assignment two classes.
Simple assignment: "=" a=b=c equivalent to A= (B=C)
Compound Assignment: "+ =" "=" "*=" "/=" "%=" "|=" "^=" "<<=" ">>=" a+=10 equivalent to A=a+10
3. Comparison operator
Comparison operators are used to compare the size of two expressions, such as greater than (>) < = =!= <= >=.
4. Logical operator
Logic and (&&) logic or (| |) and logical non (!)
5. Bitwise operators are operators that perform operations on the data by bits. C # Bitwise operators include bitwise-and (&) | ~ << >>
Using System;
Class Mikecat
{
public static void Main ()
{
int a=6&3;
Console.WriteLine ("A={0}", a);
6 binary is the binary of the 00000110,3 is 00000011, bitwise and after is equal to 00000010, that is 2
int b=6|3;
Console.WriteLine ("B={0}", b);
The binary of 6 is the binary of the 00000110,3 is 00000011, bitwise or after is equal to 00000111, that is 7
int c=~6;
Console.WriteLine ("C={0}", c);
The 6 binary is 00000110, and the reverse is 11111001-7.
int d=6^3;
Console.WriteLine ("D={0}", D);
The binary of 6 is the binary of the 00000110,3 is 00000011, bitwise XOR or after is equal to 00000101, that is 5
int e=6<<3;
Console.WriteLine ("E={0}", E);
The 6 binary is 00000110, and the left three digits equals 00101000, or 48.
int f=6>>2;
Console.WriteLine ("F={0}", f);
The 6 binary is 00000110, and the right two-bit equals 00000001, or 1.
}
}
6.is operator
The IS operator is used to check whether the Run-time object type is compatible with the given type. E is an expression in the expression "E is T", and T is a type. The return value is a Boolean value.
An IS expression evaluates to a true value if the following two conditions are true:
expression is not null.
Expression can be converted to type. That is, a transformation expression that completes the form (type) (expression) without throwing an exception.
Example
Cs_keyword_is.cs
The IS operator
Using System;
Class Class1
{
}
Class Class2
{
}
public class Istest
{
public static void Test (Object o)
{
Class1 A;
Class2 b;
If (O is Class1)
{
Console.WriteLine ("O is Class1");
A = (CLASS1) o;
Do something with a
}
else if (O is Class2)
{
Console.WriteLine ("O is Class2");
b = (Class2) o;
Do something with B
}
Else
{
Console.WriteLine ("O is neither Class1 nor Class2.");
}
}
public static void Main ()
{
Class1 C1 = new Class1 ();
Class2 C2 = new Class2 ();
Test (C1);
Test (C2);
Test ("a string");
}
}
Output
O is Class1
O is Class2
O is neither Class1 nor Class2.
7. Ternary operator
Ternary operator (?:) Also called the condition operator. For a conditional expression "b?x:y", you always evaluate the condition B first and then judge it. If the value of B is true, the value of x is computed, otherwise the value of Y is computed. The conditional operator is the right operator, so this form of expression a? B:c? D:e is calculated as follows: a? B: (c. d:e)
8.. Operator
The dot operator is used for member access. Name1. Name2
Class Simple
{
public int A;
public void B ()
{
}
}
Simple s = new Simple ();
Variable S has two members A and B; To access these two members, use the dot operator
S.A = 6; Assign to field A;
S.B (); Invoke member function B;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.