C#基础(1)——快捷\注释\使用

输出与暂停

Consel.WriteLine("hello");
Consel.ReadKey();//暂停

快捷键

Ctrl+K+D——快速对齐代码
Ctrl+J——代码提示
Ctrl+L——删除行
Ctrl+Shift+Enter——换下行
Ctrl+Enter——换上行
Alt+↑——移动当前行,往上
Ctrl+Z——撤销
Ctrl+Y——恢复
Shift+Home——选中一行到头
Shift+End——选中一行到尾
Shift+↑——选中一行到上一行
F1——转到帮助文档
折叠代码:

#region 这些是冗余代码
代码
#endregion

注释

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

namespace ChuangzhiConsel
{
    class Program
    {
        static void Main(string[] args)
        {
        }
        /// <summary>
        /// 取最大值
        /// </summary>
        /// <param name="n1">第一个参数</param>
        /// <param name="n2">第二个参数</param>
        /// <returns></returns>
        public static int GetMax(int n1, int n2)
        {
            return n1 > n2 ? n1 : n2;
        }
    }

    /// <summary>
    /// 用来描述信息
    /// </summary>
    public class Person
    {

        public string name
        {
            get;
            set;
        }
        public int age
        {
            get;
            set;
        }
    }
}

类型

string 字符串””
char 字符”
decimal money=5000m;金钱类型一定要有m
这里写图片描述
double
这里写图片描述
float
这里写图片描述
int
这里写图片描述

变量使用规则

先声明、再赋值,最后使用。

String与string的区别

运行没区别,String是系统的,string是C#里的关键字,最后都映射到同一个。
这里写图片描述

像Python一样使用占位符:
安装挖坑的顺序输出。

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

namespace ChuangzhiConsel
{
    class Program
    {
        static void Main(string[] args)
        {
            String name1 = "张三";
            String name2 = "李四";
            Console.WriteLine("hello,{0} with {1}",name1,name2);
            Console.ReadKey();
        }

    }


}

这里写图片描述

变量命名规则

保证变量名有实际意义,Camel,首单词首字母小写,区别的单词大写。字母开头、下划线、数字等组成,大小写敏感。HTML是不区分大小写的。变量名不允许重复的声明和定义。

类或方法命名

每个单词首字母大写,Pascal

不使用第三方变量交换

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

namespace ChuangzhiConsel
{
    class Program
    {
        static void Main(string[] args)
        {
            int n1, n2;
            n1 = 35;
            n2 = 655;
            n1 = n1 - n2;
            n2 = n1 + n2;
            n1 = n2 - n1;
            Console.WriteLine("n1是{0},n2是{1}",n1,n2);
            Console.ReadKey();
        }

    }


}

这里写图片描述

控制台程序

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

namespace ChuangzhiConsel
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("n1是:");
            String str = Console.ReadLine();//接收控制台的输入
            Console.WriteLine("n1是{0}", str);
            Console.ReadKey();
        }

    }


}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

何以问天涯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值