二、C#—第一个c#程序(2)

🌻🌻 目录

一、编写第一个C#程序

1.1 使用Visual Studio创建c#程序的步骤

1.2 编写第一个程序"Hello Word"

编写两行代码:

csharp 复制代码
Console.WriteLine("Hello word");  //将来指定的字符串值(后跟当前行终止符)写入标准输出流
Console.ReadLine();  //从标准输入流读取下一行字符

1.3 c#程序的基本结构

1.3.1 c#中的命名空间

(1)概念

c#程序中的一种代码组织形式,主要用来标识类的可见范围。

错误列表的显示

csharp 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Demo;

namespace Helloword
{


    class Program
    {
        Test test = new Test();

        static void Main(string[] args)
        {
            Console.WriteLine("Hello word");  //将来指定的字符串值(后跟当前行终止符)写入标准输出流
            Console.ReadLine();  //从标准输入流读取下一行字符
        }
    }
}

namespace Demo
{
    class Test
    {
    }
}

1.3.2 c#中的类

一种数据结构,存储数据成员方法成员其它类等内容,便于调用(使用)。


csharp 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Helloword
{


    class Program
    {
    }
    class Test
    {
    }
    class Test1
    {
    }

    class Test  //一个命名空间下面不能定义同样的类
    {
    }
}

1.3.3 c#中的程序启动器------Main方法

Main方法的基本要求

例如:

(1)

csharp 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Helloword
{


    class Program
    {

        static int Main(String[] args)
        {

            Console.WriteLine("Hello World");

            Console.ReadLine();

            return 0;
           
        }
    }
}

(2)

Main方法常见错误
错误提示1:

错误提示2:


错误提示3:


解决:

运行如下:

1.3.4 c#中的标识符

标识符的两个命名注意事项

下面哪些为合法的标识符

1.3.5 c#中的关键字

1.3.6 c#中的语句

c#语句实质上就是实现各种功能的c#代码

1.3.7 c#中的注释

注释:理解代码表明的意思,应用,不被执行的语句
分类

(1)行注释

(2)块注释

1.4 程序编写规范

为什么需要规范

1.4.1 代码编写规则

1.4.2 程序的两种命名方法

1.4.3 程序中元素的命名规范

相关推荐
ze言3 小时前
为什么现代 C++ (C++11 及以后) 推荐使用 constexpr和模板 (Templates) 作为宏 (#define) 的替代品?
开发语言·c++
Jinkxs4 小时前
高级15-Java构建工具:Maven vs Gradle深度对比
java·开发语言·maven
ccut 第一混4 小时前
c# winform 调用 海康威视工业相机(又全又细又简洁)
开发语言·c#·工业相机·海康威视
weixin_447103587 小时前
winform中的listbox实现拖拽功能
c#·winform
red润7 小时前
let obj = { foo: 1 };为什么Reflect.get(obj, ‘foo‘, { foo: 2 }); // 输出 1?
开发语言·javascript·ecmascript
froginwe118 小时前
PHP MySQL Delete 操作详解
开发语言
Nep&Preception8 小时前
vasp计算弹性常数
开发语言·python
伽蓝_游戏8 小时前
UGUI源码剖析(3):布局的“原子”——RectTransform的核心数据模型与几何学
ui·unity·架构·c#·游戏引擎·游戏程序·几何学
DIY机器人工房9 小时前
一个基于 epoll 实现的多路复用 TCP 服务器程序,相比 select 和 poll 具有更高的效率
开发语言·嵌入式硬件·php·嵌入式·diy机器人工房