[Language] C # Travel _ ② _ basic expression Application

Source: Internet
Author: User
Tags bitwise operators

Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{

 

/* Apply expressions */
// Operator priority:
// Metaoperator: (x), x. y, f (x), a [X], X ++, X --, new, typeof, sizeof, checked, uncheck
// Unary operator: + ,-,~! , ++ X, -- X, (t) x
// Arithmetic Operators: +,-, *,/, and %
// Bitwise operators: <, >>, &, |, ^ ,~
// Relational operators: <,>, <=,> =, is, and
// Logical operators: &, |, ^
// Conditional operators: &, | ,?
// Assignment operators: =, + =,-=, * =,/=, <=, >>=, & =, ^ =, and | =
// All operators except the value assignment operator are left-bound.

// Arithmetic Operators
Int A = 10;
Int B = 20;
Int c = 3;
Int x = A + B;
Int y = 1 + 4;
Int z = 1 +;
Int P = B-;
Int q = B/y;
Int T = A * C;
Int u = A % C;
Int v = A ++;
Int W = ++ B;
Console. writeline ("A + B =" + x );
Console. writeline ("1 + 4 =" + y );
Console. writeline ("1 + A =" + Z );
Console. writeline ("B-A =" + p );
Console. writeline ("B/5 =" + q );
Console. writeline ("A * c =" + t );
Console. writeline ("A % C =" + U );
Console. writeline ("A ++ =" + V + "A =" + );
Console. writeline ("+ + B =" + W );

// Relational operators
String a1 = "hello ";
String a2 = "hello ";
String a3 = "hey ";
If (a1 = a2)
{
Console. writeline ("Equal ");
Console. writeline (a1 = a2). tostring ());
}
Else
{
Console. writeline ("not equal ");
Console. writeline (a1 = a2). tostring ());
}
If (a1 = A3)
{
Console. writeline ("Equal ");
Console. writeline (a1 = A3). tostring ());
}
Else
{
Console. writeline ("not equal ");
Console. writeline (a1 = A3). tostring ());
}

// Logical operators
Bool mybool = true;
Bool nottrue =! Mybool;
Bool Yu = mybool & nottrue;
Bool oth = true;
If (Yu & OTH)
{
Console. writeline ("true ");
}
Else
{
Console. writeline ("false ");
}
Int res = 1;
If (convert. toboolean (RES ))
{
Console. writeline ("true ");
}
Else
{
Console. writeline ("false ");
}

// Bitwise Operator
Int resu = 4;
Console. writeline (resu <1). tostring ());
Console. writeline (resu & res). tostring ());
Console. writeline ((~ Resu). tostring ());

// Value assignment operator
Int B1, B2, B3, B4;
B1 = b2 = B3 = B4 = 1;
B1 + = 1;
B2 = B2 + 1;
B3 <= 1;
B4 & = 1;
Console. writeline (b1 + "" + B2 + "" + B3 + "" + B4 );

// Conditional Operators
Bool C1 = true;
String C2 = C1? "True": "false ";
Console. writeline (c2.tostring ());


Console. readkey (); // wait for the user to enter
}
}
}

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.