C#中的out和ref关键字

out和ref都使用引用传递将参数传入方法,out和ref的主要区别,ref使用时必须对传入的参数进行初始化,out对传入的参数在方法中必须赋值,否则会报错“控制离开方法之前必须对out参数赋值”

 class Program
    {
        public static void Change0(out int a, out int b, out string str) {
            a = 1;
            b = 2;
            str = "str发生改变---Change0";

        }
        public static void Change1(ref int a, ref int b, ref string str)
        {
            a = 3;
            b = 4;
            str = "str发生改变---Change1";

        }

        static void Main(String[] args) {
            string str="123";
            int a=0, b;

            Program.Change0(out a, out b, out str);
            Console.WriteLine("a=" + a + " b=" + b + " str=" + str);
            Program.Change1(ref a, ref b, ref str);
            Console.WriteLine("a=" + a + " b=" + b + " str=" + str);
            Console.ReadKey();

        }
    }

执行结果如下:
这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Protection Options for 百度刷相关搜索-刷下拉列表框软件V1.0.exe -------------------------------------------------------------- Macros Information ------------------ VM Macros: 0 CodeReplace Macros: 0 ENCRYPT Macros: 0 CLEAR Macros: 0 CHECK_PROTECTION Macros: 0 CHECK_CODE_INTEGRITY Macros: 0 Protection Options ------------------ Anti-Debugger: Advanced Anti-Dumpers: ENABLED Entry Point Obfuscation: ENABLED Resource Encryption: ENABLED VMWare compatible: ENABLED API-Wrapping Level: Level 2 Anti-Patching: None Metamorph Security: ENABLED Memory Guard: ENABLED When Debugger Found: Display Message Application compression: ENABLED Resources compression: DISABLED SecureEngine compression: ENABLED Anti-File Monitor: ENABLED Anti-Registry Monitor: ENABLED Delphi/BCB form protection: ENABLED Ring-0 Protection: DISABLED Virtual Machine Settings ------------------------ Number of Virtual APIs wrapped: 0 API Virtualization Level: 1 Entry Point Virtualization: 0 instructions Multi Branch Technology: DISABLED Virtual Machine Processor: Mutable CISC processor Number of CPUs: 1 Opcode Type: Metamorphic - Level 2 Dynamic Opcode: 20% Dynamic Trial Settings -------------- Days Expiration: 1 Executions: 3 Runtime: 10 Clock Change: 1 hour Trial Extension: DISABLED With single file: extendkey.dat Registration Settings --------------------- Signature Level: 等级2 With Single file: regkey.dat Only Hardware locked keys: DISABLED Only Temporary keys: DISABLED Only runs when registered: DISABLED Clear Trial when registered: DISABLED Advanced Protection Options --------------------------- Encrypt Application: ENABLED DLL plugin: DISABLED Export Generators: ENABLED Keep Trial Running: DISABLED Hide from PE scanners: Standard .NET assemblies: ENABLED Active Context: DISABLED Custom Event: Add Manifest: Don't add manifest Launch Application: XBundler files -------------- No files to bundle
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Maybe_ch

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值