C# 学习 3

方法

using System;

namespace ConsoleApp1 {
    class Program {
        static void Main(string[] args) {
           
            Program program = new Program();
            program.MyMethod();
            program.MyMethod2();
            program.MyMethod3(1,"123");
            int a = 50;
            program.MyMethod4(ref a);
            print(a);
            int b;
            program.MyMethod5(out b);
            print(b);
            Console.ReadKey();
        }
        public static void print(object obj) {
            Console.WriteLine(obj);
        }
        public void MyMethod() {
            Console.WriteLine("我是一个自定义方法");
        }
        public int MyMethod2() {
            return 20;
        }
        public void MyMethod3(int a,string b) {
            Console.WriteLine(a);
            Console.WriteLine(b);
        }
        public void MyMethod4(ref int a) {
            a += 10;
        }
        public void MyMethod5(out int a) {
            a = 10;
            a -= 5;
        }
    }
}

using System;

namespace ConsoleApp2 {
    class Program {
        static void Main(string[] args) {
            //第一种方式
            Nullable<short> na = null;
            //第二种方式
            int? a = null;
            //双问号的使用
            int c = a ?? 10;

            print(a);
            print(c);

        }
        public static void print(object obj) {
            Console.WriteLine(obj);
        }
    }
}

数组

            int[] arr = new int[2];
            arr[0] = 1;
            arr[1] = 1;

            int[] arr1 = new int[3] { 1, 2, 3 };
            int[] arr2 = new int[] { 1, 2, 3 };
            int[] arr3 = { 1, 2, 3 };

string

            string a = "hello world";
            string b = "hello";
            //a包含b
            print(a.Contains(b));
            //a相同b
            print(a.Equals(b));
            //a以b开头
            print(a.StartsWith(b));
            //a以b结束
            print(a.EndsWith(b));
            //返回下标
            print(a.IndexOf("wo"));
            //格式替换
            string c = "hello{0} world{1}";
            print(string.Format(c,"你好","世界"));

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值