Learning C # basic cases

Source: Internet
Author: User

[Csharp] // Random number Random r = new Random (); while (true) {int I = r. next (1, 7); Console. writeLine (I); Console. readKey () ;}// specifies the delimiter array, returns a string str = "my name is lei"; char [] a = {''}; string [] B = str. split (a, StringSplitOptions. removeEmptyEntries); for (int I = 0; I <B. length; I ++) {Console. writeLine (B [I]);} Console. readKey (); // returns the Console in reverse order. writeLine ("enter a string"); string a = Console. readLine (); string [] d =. split (''); for (int I = d. length-1; I> = 0; I --) {Console. write (d [I] + "");} Console. readKey (); // ignore case-insensitive string a = "a"; string B = "A"; if (. equals (B, StringComparison. ordinalIgnoreCase) {Console. writeLine ("same");} else {Console. writeLine ("different");} Console. readKey (); // replace string a = "2008-11-12"; string [] B =. split ('-'); Console. writeLine ("{0}-{1}-{2}", B); Console. readKey (); // The 9 th multiplication table for (int I = 1; I <= 9; I ++) {for (int j = 1; j <= I; j ++) {Console. write ("{0} X {1} = {2: 00}", I, j, I * j);} Console. writeLine ();} Console. readKey (); // determines whether the specified substring string [] strc = {"xxoo", "TMD", "Harmony"}; string a = Console. readLine (); int I; for (I = 0; I <. length; I ++) {if (. contains (strc [I]) {break ;}} if (I <. length) {Console. writeLine ("invalid character");} else {Console. writeLine ("valid");} // daffodils rule // int I = 1*1*1 + 5*5 + 3*3; // calculate the daffodils of 100_999 for (int I = 100; I <= 999; I ++) {// detach a 10th percentile from int ge = I % 10; int shi = I/10% 10; int bai = I/100; // determine if (I = ge * ge + shi * shi + bai * bai) {Console according to the daffodils rule. writeLine (I) ;}} Console. readKey (); // calculate the even number of bytes 100 and int sum = 0; for (int I = 1; I <=; I ++) {// if I can be divisible by 2, it indicates that this number is an even number if (I % 2www.2cto.com
= 0) {+ = I; Console. WriteLine (I) ;}} Console. WriteLine (sum); Console. ReadKey ();}

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.