C # Syntax Basics (relationships, logic, conditions, assignment operators)

Source: Internet
Author: User

Relational operators:> < >= <= and = = (equals)! = (Not equal)

Logical operator:&& (with) | | (OR)! (non, highest priority)

Assignment operator: = + = = *=/=%= Example: X-=4 is x=x-4

Conditional operator:? A:b if it is true to execute a, otherwise execute B

For a few examples:

A multiple of ①7, 10 digits is 7, the single digit is the number of 7

Console.WriteLine ("Please enter the number within 100");
int a = Int. Parse (Console.ReadLine ());
Console.WriteLine (a% 7 = = 0); The number that is divisible by 7
Console.WriteLine (A/10 = = 7);//10 digits is 7
Console.WriteLine (A%10 = = 7);//single digit is 7
Console.readkey ();

Ii

Console.WriteLine ("Please enter 2 Chinese characters");
String a1,a2;
A1 = Console.ReadLine ();
A2 = Console.ReadLine ();
Console.WriteLine (a1 = = "Hello");
Console.WriteLine (a1 = = "Hello" && a2 = = "Classmate");
Console.WriteLine (a1 = = "Hello" | | a2 = = "Classmate");
Console.WriteLine (! ( A1 = = "Hello" && a2 = = "Classmate");
Console.readkey ();

Console.WriteLine ("Please enter 2 values within 10 and add equals 15");

int b2 = Int. Parse (Console.ReadLine ());
int B3 = Convert.ToInt32 (Console.ReadLine ());
Console.WriteLine (B2 + b3 ==15?) "Answer right": "Answer the wrong, drag out the castrate!" ");
Console.readkey ();

Standard Weight:

Men's weight-height +100=±3; women's weight-height +110=±3;

String XB;
Double TZ, SG;
Console.WriteLine ("Judging whether a person's weight is a standard weight");
Console.Write ("Gender:");
XB = Console.ReadLine ();
Console.Write ("Weight (kg):");
TZ = Double. Parse (Console.ReadLine ());
Console.Write ("Height (cm):");
sg = convert.todouble (Console.ReadLine ());
int y = XB = = "Male"? 100:110;
Console.WriteLine (tz-sg+y<-3? ") Too skinny ":(tz-sg+y<=3)?" Perfect ":" Too fat ");

Console.readkey ();

int B = 1, c = 1, d = 1, E = 1, f = 1;
B + = 3;
c-= 3;
D *= 3;
e/= 3;
F%= 3;
Console.WriteLine (B.tostring ());
Console.WriteLine (C.tostring ());
Console.WriteLine (D.tostring ());
Console.WriteLine (E.tostring ());
Console.WriteLine (F.tostring ());

Console.readkey ();

C # Syntax Basics (relationships, logic, conditions, assignment operators)

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.