零基础C#学习笔记之基础部分(三)

1.命名:
变量用驼峰法;
其他命名空间、类、函数等用Pascal方法;
2变量类型
int(32bit)long(64bit)

int x = 2;
long y = 3L;
float z = 3.0F;
double m = 4.0D;
char c = 'c';
string str = "123";
bool b = true;
//行注释;
/*块注释
*/

提示:ctrl+k+d可以快速整理杂乱的代码;
快速注释代码:选中然后ctrl+KC;取消注释:ctrl+KU;
var 声明隐式类型变量;(C#是强类型语言,变量的类型一旦确定就不能改变)
常量的定义:后面必须跟着初始化器:

const int x = 100;

3.一些例程:

var x = 4;
Console.WriteLine(x.GetType().Name);

输出结果:Int32

using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassAndInstance3
{
    class Program
    {
        static void Main(string[] args)
        {
            Calculator c = new Calculator();
            int x = c.Add(3, 4);
            Console.WriteLine(x);//cw+两下tab即可快速打出
        }


        class Calculator
        {
            public int Add(int a, int b)
            {
                int result = a + b;
                return result;
            }
        }

    }
}

输出结果为7.

using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassAndInstance3
{
    class Program
    {
        static void Main(string[] args)
        {
            Day d = new Day();
            string sayDay = d.GetDay();
            Console.WriteLine(sayDay);
        }


        class Day
        {
            public string GetDay()
            {
                int day = DateTime.Now.Day;
                return day.ToString();
            }
        }

    }
}

输出:5
正确
4.使用performance monitor查看进程的堆内存使用量。
5.可以使用如下方法看不同数字变量的最大最小值范围:

uint x = uint.MaxValue;
            Console.WriteLine(x);
            sbyte y = sbyte.MinValue;
            Console.WriteLine(y);
            sbyte z = sbyte.MaxValue;
            Console.WriteLine(z);

输出结果:
4294967295
-128
127
还可以:

string binStr = Convert.ToString(y, 2);
            Console.WriteLine(binStr);

输出:1111111110000000
含义:转成2进制表示;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值