c# 入门

本文详细介绍了C#的基础语法,包括变量定义、字符串处理、数组操作、常量使用及动态类型等核心概念,并通过示例代码展示了这些语法的实际应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

        byte b = 220;  //无符号,到255
        sbyte sb= 127; //有符号,-128到127之间

        Object obj = 100;// 对象类型转换为基本类型,自动装箱;

        string s = "hello\t\tworld";  //拥有转义字符制表符
        string s1 =@"hello\t\tworld"; //使用@会让转义字符失效;
        Console.WriteLine(s); 
        Console.WriteLine(s1);

        int[] arr = new int[] { 1,2,5,7,9,5,6, }; //foreach循环
            foreach (int num in arr ) 
        {
            Console.WriteLine(num);
        }

        const double pi = 3.14159; // 使用const来对一个常量声明
        Console.WriteLine(sizeof(float)); //每个类型的大小
        dynamic d = "dfs"; //动态类型,运行时下回确定的
        Console.WriteLine(b);//输出且换行
        Console.WriteLine("hello world");
        Console.ReadKey();//等待键盘操作

    }
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值