What is the Linq.First equivalent in PowerShell?

后端 未结 4 1011
孤城傲影
孤城傲影 2021-02-01 12:44

The snippet below detects from a list of files which of them is a Directory on Ftp

as C# it will be like below

var files = new List(){\"App         


        
4条回答
  •  囚心锁ツ
    2021-02-01 13:39

    This is a really simple implementation for First:

    function First($collection)
    {
        foreach ($item in $collection)
        {
            return $item
        }
        return $null
    }
    

    Instead of returning $null, you could throw an InvalidOperationException exception.

提交回复
热议问题