|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|