zoukankan      html  css  js  c++  java
  • 由 var grid = new WebGrid(Model, canPage: true, rowsPerPage: 2) 了解到的新的参数写法

    在 网上看到 var grid = new WebGrid(Model, canPage: true, rowsPerPage: 2)  这种写法,这种.net2.0,3.X 下不支持的写法。

    在4.0 有了以下的写法:

    1 using System;
    2  using System.Collections.Generic;
    3  using System.Linq;
    4  using System.Text;
    5
    6  namespace ConsoleApplication1
    7 {
    8 class Program
    9 {
    10 //
    11 static string GetString(string a, string b)
    12 {
    13 return a + b;
    14
    15 }
    16
    17 static void Main(string[] args)
    18 {
    19 //实例化类(有参的构造函数)
    20 cs c = new cs(a: "a1", b: "b1");
    21 //.net 2.0不支持的写法
    22 string str = GetString(a: "g", b: "c");
    23 Console.WriteLine(str);
    24 }
    25 }
    26 class cs
    27 {
    28 public cs(string a, string b)
    29 {
    30 }
    31 }
    32
    33
    34 }

    个人认为:这样的写法在方法多个重载,类有多个构造函数时,对参数的说明有很大的好处,增加了代码的可读性

  • 相关阅读:
    储存过程与触发器
    session 和 cookie
    (四)Jira工作流状态的属性
    (三)Jira scriptrunner插件
    (二)JIRA安装
    vs2015 调试无法访问网站的问题
    设计模式
    依赖倒置、反射、泛型、委托、AOP
    C# .NET
    持续集成
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2097940.html
Copyright © 2011-2022 走看看