Select items in List that match an interface

前端 未结 2 1990
误落风尘
误落风尘 2021-01-07 00:52

I have the following Interfaces defined:

public interface IStep 
{
    string Name { get; set; }
}

public interface IStepBuildDataSet : IStep
{
    DataSet          


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-07 01:07

    You could use OfType to make it abit cleaner like this:

    IStepBuildDataSet buildDataSet = Steps.OfType().Single();
    IStepBuildFile buildFile = Steps.OfType().Single();
    

    Notice, you dont need to cast the results, since OfType does that for you.

提交回复
热议问题