Determine if collection is of type IEnumerable

后端 未结 9 2010
轻奢々
轻奢々 2020-12-12 23:50

How to determine if object is of type IEnumerable ?

Code:

namespace NS {
    class Program {
        static IEnumerable GetInts()         


        
9条回答
  •  春和景丽
    2020-12-13 00:28

    You can use the is keyword.

    [TestFixture]
    class Program
    {
        static IEnumerable GetInts()
        {
            yield return 1;
        }
    
        [Test]
        static void Maasd()
        {
            var i = GetInts();
            Assert.IsTrue(i is IEnumerable);
        }
    }
    

提交回复
热议问题