using System;
namespace OnlineCSharpExample
{
class Program
{
static void Main(string[] args)
{
// 这是一个简单的 C# 程序,用于在线运行和测试。
Console.WriteLine("Hello, World!");
// 示例:定义一个变量并输出
int number = 10;
Console.WriteLine("The number is: " + number);
// 示例:使用 if-else 语句
if (number > 5)
{
Console.WriteLine("The number is greater than 5.");
}
else
{
Console.WriteLine("The number is not greater than 5.");
}
// 示例:使用 for 循环
Console.WriteLine("Printing numbers from 1 to 5:");
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i);
}
// 示例:定义一个方法并调用
int result = AddNumbers(3, 7);
Console.WriteLine("The sum of 3 and 7 is: " + result);
}
// 定义一个简单的加法方法
static int AddNumbers(int a, int b)
{
return a + b;
}
}
}
OnlineCSharpExample 是命名空间,Program 是类。在 C# 中,代码通常放在类中。number 并赋值为 10。AddNumbers 的方法,用于计算两个整数的和,并在主程序中调用该方法。这个示例代码展示了如何编写一个简单的 C# 程序,并包含了基本的语法结构和常用功能。
上一篇:c#回调函数
下一篇:c# file
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站