当前位置:网站首页>C#简单介绍
C#简单介绍
2022-06-12 17:53:00 【锄禾吖】
C# 是一个简单的、现代的、通用的、面向对象的编程语言。
一个 C# 程序主要包括以下部分:
- 命名空间声明
- 一个 class
- Class 方法
- Class 属性
- 一个 Main 方法
- 语句和表达式
以下创建一个cs文件,文件包含了可以打印出 “Hello World” 的简单代码:
using System;
namespace Name
{
class HelloWorld
{
static void Main(string[] args)
{
/* 这是一个 C# 程序*/
Console.WriteLine(“Hello World”);
}
}
}
执行后是这样的:
让我们好好分析写的代码都是什么意思:
程序的第一行using System,using关键字用于在程序中包含System命名空间。一个程序一般有多个using语句。
下一行是namespace声明。一个 namespace 里包含了一系列的类。Name命名空间包含了类 HelloWorld。
下一行是 class 声明。类 HelloWorld 包含了程序使用的数据和方法声明。类一般包含多个方法。方法定义了类的行为。在这里,HelloWorld 类只有一个 Main 方法。
下一行定义了 Main 方法,是所有 C# 程序的 入口点。Main 方法说明当执行时 类将做什么动作。
下一行 /…/ 将会被编译器忽略,且它会在程序中添加额外的注释。
Main 方法通过语句 Console.WriteLine(“Hello World”)。指定了它的行为。WriteLine 是一个定义在 System 命名空间中的 Console 类的一个方法。该语句会在屏幕上显示消息 “Hello World”。
以下几点值得注意:C# 是大小写敏感的、所有的语句和表达式必须以分号(;)结尾、程序的执行从 Main 方法开始、与 Java 不同的是,文件名可以不同于类的名称。
边栏推荐
- Use applet to quickly generate app in seven steps
- Recognize function originality
- 数据库SQL操作基础
- 在同花顺开户证券安全吗
- SSM integrates FreeMarker and common syntax
- Notes on user experience elements: user centered product design
- Figma从入门到放弃
- Nixos 22.05 installation process record
- I heard that distributed IDS cannot be incremented globally?
- Learn the mitmproxy packet capturing tool from scratch
猜你喜欢

JDBC几个坑

Nixos 22.05 installation process record

文章名字
Goframe gredis configuration management | comparison of configuration files and configuration methods

轻量、便捷的小程序转App技术方案,实现与微信/流量App互联互通

Small program +app, a low-cost and active technology combination idea

Exclusive interview with oppo find X5 Product Manager: deeply cultivate self-developed chips to create the ultimate flagship experience with the highest standards

赛程更新| 2022微软与英特尔黑客松大赛火热报名中

字节飞书人力资源套件三面

C operation database added business data value content case school table
随机推荐
String s = null ; String s = new String();String s =““ ;String s ;有什么区别?
566. 重塑矩阵
認識函數原創
Detailed description of SQL cursor and example of internal recycling
Use of split method of string
String s = null ; String s = new String(); String s = "; what is the difference between string s?
Is it cost-effective to apply for Huagui sweet home term life insurance? What are the advantages of this product?
566. reshaping the matrix
1.5 what is an architect (serialization)
EASYCODE template
利用小程序快速生成App,只需七步
Are Huishang futures accounts reliable? Is the fund safe?
Figma从入门到放弃
Arm64栈回溯
徽商期货公司开户可靠,交易安全吗?
SQL游标(cursor)详细说明及内部循环使用示例
论文《Deep Interest Evolution Network for Click-Through Rate Prediction》
使用MongoDB官方go库操作MongoDB原创
Tcp/ip family structure and protocol of tcp/ip series overview
Arm64棧回溯