You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
745 B
C#

6 years ago
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
namespace LinqStudy.Test.LinqToObject
{
public class OtherTest
{
/// <summary>
/// is操作符用作if条件时判断之后可以直接赋值给一个变量.(输出给变量)
/// 其它地方可以用as实现相同功能
/// </summary>
/// <example>
/// if (id is List-int output){output.Add(1);}
/// </example>
[Fact]
public void Is_Test()
{
List<int> id = new List<int>();
if (id is List<int> output)
{
output.Add(1);
}
var cc = id as List<int>;
cc.Add(1);
}
}
}