c#语句中的逗号

本文关键字:语句 | 更新日期: 2023-09-27 18:11:17

我正在检查这段代码(用c#写的):

string root = match.Groups[1].Value,
                secon = match.Groups[2].Success ? match.Groups[2].Value.Substring(1) : string.Empty,
                third = match.Groups[3].Success ? match.Groups[3].Value.Substring(1) : string.Empty;

谁能解释一下逗号的作用?

c#语句中的逗号

声明3个类型为string的变量,分别命名为rootseconthird。这样的:

int a, b, c;

这是一个语法快捷方式。上面的例子是语法糖,与

完全相同
string root  = match.Groups[1].Value   ;
string secon = match.Groups[2].Success ? match.Groups[2].Value.Substring(1) : string.Empty ;
string third = match.Groups[3].Success ? match.Groups[3].Value.Substring(1) : string.Empty ;

所以它节省了你输入的时间。

它们被用作创建变量的快捷方式,并且,在您的示例中,所有这些变量的类型都是string