C#参数使用场景简要说明

C#参数使用场景简要说明

1、传值参数

方法、类成员的初始化

2、输出参数

方法返回值不能满足,需要多个返回值时;

3、引用参数

方法需要修改变量需带回原变量时;

4、具名参数

代码可读性高,参数可交换位置

5、方法扩展(this参数)

方法扩展时,目前不存在满足的方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
//this参数(扩展方法)
namespace PamametersExample9
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> vs = new List<int>() { 11, 21, 13, 1, 15 };
            bool b = AllCreateThanTen(vs);
            //lambda表达式
            bool b1 = vs.All(i => i > 10);
            Console.WriteLine(b);
            Console.WriteLine(b1);
        }
        static bool AllCreateThanTen( List<int> vs)
        {
            foreach (var item in vs)
            {
                if (item <= 10)
                {
                    return false;
                }
            }
            return true;
        }
    }
}

6、可选参数

参数拥有默认值

7、数组参数

简化方法的调用,不需要额外声明数组

相关推荐

  1. C#参数使用场景简要说明

    2024-06-15 22:46:02       29 阅读
  2. WordPress WP_Query参数使用说明

    2024-06-15 22:46:02       45 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-15 22:46:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-15 22:46:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-06-15 22:46:02       82 阅读
  4. Python语言-面向对象

    2024-06-15 22:46:02       91 阅读

热门阅读

  1. 编程入门教育游戏教案:打造互动式学习体验

    2024-06-15 22:46:02       26 阅读
  2. 数据库和DDL语句

    2024-06-15 22:46:02       28 阅读
  3. numpy.fft 与 torch.fft函数使用

    2024-06-15 22:46:02       31 阅读
  4. Python面试官:什么是自省

    2024-06-15 22:46:02       27 阅读
  5. ADB调试命令大全

    2024-06-15 22:46:02       16 阅读
  6. C# —— switch语句

    2024-06-15 22:46:02       21 阅读
  7. linux 文件删除空间未释放问题

    2024-06-15 22:46:02       21 阅读
  8. 工厂方法模式和抽象工厂

    2024-06-15 22:46:02       25 阅读