• 推荐
  • 评论
  • 收藏

由 var grid = new WebGrid(Model, canPage: true, rowsPerPage: 2) 了解到的新的参数写法

2022-12-08    8806次浏览

在 网上看到 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 }

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

原文地址:https://www.cnblogs.com/Leo_wl/p/2097940.html