zoukankan      html  css  js  c++  java
  • 20140830 函数 递归

    1. ref,函数形参变量的输入有两种方式:传值,传址。而ref则为传址。
    2. out,顾名思义,即输出。相当于一个函数可以有多个返回值,这是C#中特有的
    3. params,在数组形参前面使用,可以赋多个值。
    4. enum,枚举是由程序员定义的类型,与类或结构一样。

    例如

     //static void Add(ref int n)
                //static void Add(int n)
              static int Add(int n,out int p)
            {
                int m = n * 10;
                p = m;
               // Console.WriteLine("Add函数1:{0}", n);
                n = n + 10;
                //Console.WriteLine("Add函数2:{0}", n);
                return n;
            }
            static void Main(string[] args)
            {
                int a = 5;
               // Console.WriteLine("Main函数1:{0}", a);
               // Add(a);
               // Add(ref a);
                int b;
                a = Add(a,out b );
    
                Console.WriteLine("a={0}b={1}", a, b);
               // Console.WriteLine("Main函数2:{0}", a);

    递归,递归的特点就是自己调用自己;return 是将数值返回上一级

    例如:

            static int taozi(int day)
            {
                if (day == 10)
                {
                    return 1;
                }
    
               int now=( taozi(day + 1)+1)*2;
               return now;
            }
            static void Main(string[] args)
            {
                //递归
                int n = taozi(1);
                Console.WriteLine("公园里有{0}个桃子", n);
  • 相关阅读:
    重构后的ConditionHelper
    重构ConditionHelper
    用shell求两个文件的差集
    文件落盘的逻辑
    [转]undefined reference问题总结
    动态生成xml文件
    32位,64位的一些问题
    树数据结构的实际应用
    线程池中的栅栏
    关于线程池的理解
  • 原文地址:https://www.cnblogs.com/jackjms/p/3949105.html
Copyright © 2011-2022 走看看