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
    }
    }

  • 相关阅读:
    我的WCF之旅(1):创建一个简单的WCF程序
    网页设计中颜色的搭配
    CSS HACK:全面兼容IE6/IE7/IE8/FF的CSS HACK
    UVa 1326 Jurassic Remains
    UVa 10340 All in All
    UVa 673 Parentheses Balance
    UVa 442 Matrix Chain Multiplication
    UVa 10970 Big Chocolate
    UVa 679 Dropping Balls
    UVa 133 The Dole Queue
  • 原文地址:https://www.cnblogs.com/sumg/p/3742759.html
Copyright © 2011-2022 走看看