1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { double a = 5.456; int b = 15; Console.WriteLine(a); Console.WriteLine("Hello world {1} {0}", a, a + b); Console.WriteLine("{0, 4:f2}", a); Console.WriteLine($"Hello world {a} {a + b}"); string str = "15 65 8 96"; Console.WriteLine(str); String[] result = str.Split(' ',','); foreach (string s in result) { Console.WriteLine($"{Convert.ToInt32(s)}"); } int[] sum = Array.ConvertAll(result, Convert.ToInt32); foreach (int s in sum) { Console.WriteLine("{0}", s); }
char flag = '5'; Console.WriteLine(char.IsNumber(flag)); string s1 = "Hello "; string s2 = "World!"; string s3 = s1 + s2; Console.WriteLine(s3[7] + s2[2]); Console.WriteLine("a" + 300 + 5 + "b"); Console.WriteLine("a" + (300 + 5) + "b");
string s4 = "nihao\nnihao"; Console.WriteLine(s4); s4 = @"nihao\nnihao"; Console.WriteLine(s4);
string s5 = "World!"; Console.WriteLine(s2 == s5);
double d1 = 1.5; float d2 = 1.0f; decimal x = (decimal)d1;
int k1= Convert.ToInt32("48"); int k2 = int.Parse("45");
int res; bool q = int.TryParse("abc", out res); Console.WriteLine($"q is {q}, res is {res}"); } } public enum Title { apple, banana, orange, } public class Student { public string name; public int age; public Title title; public Student(string name, int age) { this.name = name; this.age = age; } public void sum() { switch (title) { case Title.apple: Console.WriteLine("apple"); break; case Title.banana: Console.WriteLine("banana"); break; case Title.orange: Console.WriteLine("orange"); break; } } } }
|