Hellow 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//项目名称  
namespace ConsoleApp6
{
    //类
    internal class Program
    {
        // 方法 和 函数 
        static void Main(string[] args)
        {
            for (int i = 0; i < 5; i++) {
                Console.WriteLine(i);
            
            }
            Console.ReadKey();
        }
    }
}

  

 Console.WriteLine(i);   打印字符

Console.ReadLine(i);   接受用户的输入

 Console.ReadKey();  打印键盘输出

 

 # 技巧

 

 #折叠

 

 

 

 

变量和数据类型

(1.声明 2.赋值 3.使用)

生命只能1次 赋值可以多次  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp8
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int age = 32;
            double x = 32.2;
            string name = "张三";
            char c = 'a'; //字符类型必须 最多最少一个
            decimal d = 213123.3m; // 高精度


        }
    }
}

占位符

按照挖坑的顺序输出

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp8
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int n1 = 1;
            int n2 = 2;
            int n3 = 3;
            int n4 = 4;
            string s = "第一个是{0} 第二个{1} 第三个{2} 4{4}";
            Console.WriteLine("第一个是{0} 第二个{1} 第三个{2} 4{3}", n1,n2,n3,n4);
            Console.ReadKey();

        }
    }
}

 

转义符

@ 防止字符串转义  保留原格式输出

\n 换行 (win 不识别)  \r\n 统一换行

\" 表示字符的单引号

\t  tab键  对齐键

\b 删除键 退格键

\\  表示\

 

写入文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp8
{
    internal class Program
    {
        static void Main(string[] args)
        {
            System.IO.File.WriteAllText(@"C:\Users\Xie_Rain\Desktop\xx.txt","嘿\r\n嘿嘿");

        }
    }
}

类型转换

隐式类型转换 小的等级转大的等级 

强制类型转换 大的等级转小的等级 

兼容转换

double>int   

double new_a = (int)a;

double d1 = 3 / 2; // 1         int  / int 整除

double d2 = 3.0 / 2.0; // 1.5  # double /double > 除数 

Console.WriteLine("{0:0.00}",d);  #保留两位

 

不兼容转换

double d = Convert.ToDouble(s);

自增

a++; 或者   ++a;   

a--;   或者   -- a;

a++ 与 ++a 的区别

int a = 1 

10 + a++ 是 11  算完后 a++

10 + ++a 是12  ++a 优先级高 先++a 再运算

 

 

 

 IF 

using System;

namespace ConsoleApp8
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            if (a >= 90)
            {
                Console.WriteLine("大于等于90");
            }
            else  if (a>=80)
            {
                Console.WriteLine("大于等于80");
            }
            else
            {
                Console.WriteLine("你错了");


            }
            Console.ReadKey();
        }
    }
}

 

posted on 2022-01-25 18:35  谢Rain  阅读(34)  评论(0编辑  收藏  举报