首页 > 编程语言 >C#基本语法

C#基本语法

时间:2023-10-10 21:35:51浏览次数:36  
标签:基本 name Parent C# age 语法 int public string

基本语法

// See https://aka.ms/new-console-template for more information
// Hello World Console.WriteLine("Hello, World!"); // declare variable int x = 0; // expression x = x + 1; x = 0; // function calling logStringNTimes(x.ToString(), x); // function defining void logStringNTimes(string str, int times) { // choice structure if (times <= 0) { return; } switch (times) { case <= 0: return; default: break; } // sequential structure times++; // looping structure for (int i = 0; i < times; i++) { Console.WriteLine(str); } int times_tmp = times; while (times_tmp > 0) { Console.WriteLine(times_tmp--); } } // instantiate a class Parent parent = new Parent; parent.Name = "dad"; parent.Age = 18; // actual 19 (calling property setter)

 Parent Class defination

// object orientation
class Parent
{
    // field
    private string name;

    // property 
    public string Name { get => name; set => name = value; }
    public int Age 
    { 
        get => {
            ++age;
        }
        set => {
            age = ++value;
        }
    }

    private int age;

    // method
    public string selfIntro()
    {
        return $"name: {name}; age: {age}";
    }

    // class method 
    public static string theClassName() 
    {
        return typeof(Parent).Name;
    }
}

 

标签:基本,name,Parent,C#,age,语法,int,public,string
From: https://www.cnblogs.com/newbieking/p/17755771.html

相关文章

  • 使用C#调用7Zip解压文件
    使用C#调用7Zip解压文件可以输入密码可以省略输出的路径则默认创建压缩包同名文件夹Console.WriteLine("你好,接下来开始解压文件");ExtractArchiveWithPassword(@"E:\压缩文件测试\压缩文件_Orgion\V_1696602827.7z",......
  • [ARC130E] Increasing Minimumm
    [ARC130E]IncreasingMinimumm?考虑模拟一下题目中的过程,发现相当于将原序列按照初始值划分为若干个等价类,然后每次都会先合并等价类然后重排等价类中的所有数并加入\(I\)中。这样将\(I\)划分成了若干段。考虑假设我们一共划分出\(T\)个段,那么最终每个数的答案就是\(T\)......
  • 【Azure Developer】示例: 在中国区调用MSGraph SDK通过User principal name获取到Use
    问题描述示例调用MSGraphSDK通过Userprincipalname获取到User信息,如ObjectID。 参考资料选择MicrosoftGraph身份验证提供程序: https://learn.microsoft.com/zh-cn/graph/sdks/choose-authentication-providers?tabs=java#using-a-client-secret-2MicrosoftGraphSDKfor......
  • Programming abstractions in C阅读笔记:p176-p178
    《ProgrammingAbstractionsInC》学习第59天,p176-p178总结。一、技术总结1.addtivesequencestn=tn-1+tn-2序列:3,7,10,17,27,44,71,115,186,301,487,788,1275,...p177,Asageneralclass,thesequencesthatfollowthispatternarecalledadditivesequen......
  • 在DC上使用管理员账号,激活系统时出现““Windows 无法访问指定设备、路劲或文件。你可
    1.在增加语言选择是,也会遇到类似错误:2.在管理工具中,找到“本地安全策略”:3.进入本地策略->安全选项->用户帐户控制:用于内置管理员帐户的管理员批准模式 ->启用......
  • docker入门加实战—从部署MySQL入门docker
    docker入门加实战—从部署MySQL入门dockerdocker部署MySQL输入如下命令:dockerrun-d\--namemysql\-p3306:3306\-eTZ=Asia/Shanghai\-eMYSQL_ROOT_PASSWORD=123\mysql部署成功截图如下:当执行命令后,Docker做的第一件事情,是去自动搜索并下载了MySQL,......
  • Programming abstractions in C阅读笔记:p176-p178
    《ProgrammingAbstractionsInC》学习第59天,p176-p178总结。一、技术总结1.addtivesequencestn=tn-1+tn-2序列:3,7,10,17,27,44,71,115,186,301,487,788,1275,...p177,Asageneralclass,thesequencesthatfollowthispatternarecalledadditive......
  • CF1054D Changing Array
    题意给定\(n\)个小于\(2^k\)的数。可以任意让若干数\(xor\)\(2^k-1\)。问使得最终区间\(xor\)不为\(0\)的最大个数。Sol考虑前缀异或和。记异或和的数组为\(s\)。现在一个区间的贡献变为\(s_r\opluss_{l-1}\)。考虑何时该贡献为\(0\)。显然当\(s......
  • 报错Intel MKL FATAL ERROR: Cannot load libmkl_core.so.的一种解决方法
    问题今天上80服务器跑mdistiller的代码时,意外发现torch、numpy都不能用了T_T以torch为例,出现如下报错情况以numpy为例,出现如下报错情况我们先看看报错信息,这个报错来自InterMKL。InterMKL全称是TheIntelMathKernelLibrary,它是一个主要是用于科学计算的共享库,提供了很......
  • PCIe 5.0 SSD四合一!峰值带宽高达64GB/s
    华硕低调发布了新一代HyperM.2x16Gen5扩展卡,可以单卡安装最多四块PCIe5.0x4SSD。它采用了PCIe5.0x16系统级接口和服务器级PCB,可以提供64GB/s的峰值带宽,每块都可以跑到16GB/s。当然目前还没有能做到这一点的SSD,而考虑到带宽损耗,实际上也不可能做到。四块SSD均支持2242......