c#基础语法(第二节课后作业/笔记)

本次课程着重介绍了一些c#的语法知识,因为都是类c语言所以语法与C++和Java非常类似,在此我只着重写一些我自己认为比较重要或者掌握不太熟练的地方。

尝试了一下C#中类似于C++占位符%d这种的输出方式,其实我一直觉得C中的这样更有利于规范输出格式,而且速度比cout快,不知道在C#中有没有区别

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int aaa = 100;
            double bbb = 3.14;
            Console.WriteLine("For test {0} {1}", aaa, bbb);
            Console.ReadLine();
        }
    }
}

还有上节课老师曾经提起过这个

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 2147483647;
            short y = 0;
            Console.WriteLine("{0},{1}",x,y);
            y = x;
            Console.WriteLine("{0},{1}", x, y);
            Console.ReadLine();
        }
    }
}

类型转换的时候

y = x;

会报错,因为低类型不能被高的类型赋值。

其余的关于构造函数析构函数拷贝构造函数的代码就不一一贴出,和C++/Java的区别不大,也算是巩固了之前的知识。

还有运算符重载我们要注意一点

int func( int a )
int func( double a )
可以构成重载
但是
int func(int a)
double func( int a )
却不是重载

我们要注意参数类型不一样才可以。。。返回值不一样并不是重载。但是返回值不一样不影响重载

 Visual Studio的

#region
#endregion

可以用来折叠代码

本周的记录就是这样,再接再厉

原文地址:https://www.cnblogs.com/Durandal/p/4360700.html