zoukankan      html  css  js  c++  java
  • ref 关键字out关键字

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

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

    //ref修饰方法的参数,在调用的时候必须在变量之前加上ref关键字,只能传递变量,不能传递常量
    //传递的时候 不是传递变量的值,而是传递变量的地址
    //out 也是传递变量的地址,out必须在方法内赋值,ref可以修改其值,也可以不修改
    //out侧重输出,ref侧重修改
    static void TestOut(out int i)
    {
    i = 100;
    }
    static void TestRef(ref int i)
    {
    i++;
    }
    #region 【冒泡排序】
    static void GetMaxAndMin(int[] arr, out int max, out int min)
    {
    //Array.Sort(arr);排序
    for (int i = 0; i < arr.Length - 1; i++)
    {
    for (int j = 0; j < arr.Length - 1 - i; j++)
    {
    if (arr[j] > arr[j + i])
    {
    int temp = arr[j];
    arr[j] = arr[j + i];
    arr[j + 1] = temp;
    }
    }
    }
    max = arr[arr.Length - 1];
    min = arr[0];
    }
    #endregion

    #region[属性]
    public string name;
    public string Name //属性的返回值跟他封装的字段是没有关系的,跟他的get返回的类型有关系,也跟set赋值的类型也有关系
    {
    get {
    return name;
    }
    set
    {
    if (value == "")
    {
    name = "hello world";
    }else
    {
    name=value;
    }
    }
    }

    #endregion
    }
    }

  • 相关阅读:
    nsis打包
    学习记录:ST表
    学习记录:快速幂
    学习记录:哈夫曼树
    学习记录:二叉树
    学习记录:康托展开 与 逆康托展开
    堆排序简介
    动态规划水题集
    lower_bound( ) 与 upper_bound( )
    琐碎的一点技巧
  • 原文地址:https://www.cnblogs.com/sumg/p/3742759.html
Copyright © 2011-2022 走看看