using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
//变量
int num = 1;
char c = 'a';
float f = 1.1f;
double a = 22.3;
string str = "我是tom";
bool b = false;
Console.WriteLine(num);
Console.WriteLine(c);
Console.WriteLine(f);
Console.WriteLine(a);
Console.WriteLine(a+c);
Console.WriteLine(a+num);
Console.WriteLine(str);
Console.WriteLine(b);
//常量
const int num2 = 30;
Console.WriteLine(num2);
//> >= = < <=
Console.WriteLine(1>2);
Console.WriteLine(1 < 2);
Console.WriteLine(a>c);
//==
Console.WriteLine(1==2);
Console.WriteLine(1 != 2);
int n1 = 10;
int n2 = n1++;
int n3 = ++n1;
Console.WriteLine(n1);
Console.WriteLine(n2);
Console.WriteLine(n3);
int n4 = 10;
n4 += 5;
Console.WriteLine(n4);
int n5 = 15;
Console.WriteLine(n5%5);
int n6;
n6 = n4 + n5;
Console.WriteLine(n6);
string s1 = "123";
string s2 = "ja1";
Console.WriteLine(s1+s2);
Console.WriteLine("{0},{1},{2}",n1,s1,n5);
//类型转换
int n7 = 10;
//隐式转换
float n8 = n7;
Console.WriteLine(n8);
float n9 = 1.1f;
//显示转换
int n10 =(int)n9;
Console.WriteLine(n10);
//Convert转换
string s3 = "35";
int n12 = Convert.ToInt32(s3);
Console.WriteLine(n12);
double n13 = Convert.ToDouble(s3);
Console.WriteLine(n13);
int n14 = 5;
if (n14==0)
{
Console.WriteLine("是0啊");
}else if (n14==8)
{
Console.WriteLine("是8啊");
}
else
{
Console.WriteLine("是{0}啊",n14);
}
Console.WriteLine("\"a\"d\ts是\n{0}啊", n14);
int n15 = 1;
MyDate m = MyDate.Fri;
Console.WriteLine("是{0},{1}啊", m,(int)m);
switch ((int)m)
{
case 1:
Console.WriteLine(1);
break;
case 2:
Console.WriteLine(2);
break;
default:
Console.WriteLine(m);
break;
}
//for循环
int n16 = 0;
for (int i = 1; i < 101; i++)
{
n16 += i;
}
Console.WriteLine(n16);
//while
int n17 = 5;
while (n17>0)
{
Console.WriteLine(n17);
n17--;
}
Console.WriteLine("结束while循环");
// do while
do
{
Console.WriteLine(n17);
n17--;
} while (n17 > 0);
Console.WriteLine("结束dowhile循环");
//数组
//创建数组
int[] arr1=new int[3];
Console.WriteLine(arr1);
int[] arr2 = new int[3] {1,2,3};
Console.WriteLine(arr2[0]);
int[] arr3 = new int[] { 1, 2, 3 };
Console.WriteLine(arr3[0]);
int[] arr4 = { 4,5,1, 2, 3 };
Console.WriteLine(arr4[2]);
int b22 = arr4.Length;
Console.WriteLine(b22);
Console.WriteLine("-------------------------------------");
//遍历数组
//foreach
foreach (var item in arr4)
{
Console.WriteLine((item+1));
}
//冒泡排序
int temp;
for (int j = 0; j < arr4.Length-1; j++)
{
for (int i = 0;i < arr4.Length - 1-j;i++)
{
if (arr4[i] > arr4[i+1])
{
temp = arr4[i +1];
arr4[i + 1] = arr4[i];
arr4[i] = temp;
}
}
}
foreach (var item in arr4)
{
Console.WriteLine((item));
}
Console.ReadKey();
}
enum MyDate
{
//枚举类型
//enum
//枚举类型 是一种独特的值类型,它用于声明相同性质的常量
//作用:可以增加程序的可读性和可维护性,同时还能避免类型错误
Mon = 0,
Tue = 1,
Wed = 2,
Thu = 3,
Fri = 4,
Sat = 5,
Sun = 6
}
}
}
C# 学习
于 2022-09-05 23:05:49 首次发布