LoginSignup
1
2

More than 5 years have passed since last update.

Pythonのall(list)が便利だったので、C#/VB.netに置き換えた

Posted at

Pythonのall(list)が便利だったので、C#/VB.netに置き換えた

趣味で研究しているPythonの書き方が便利だったので、.Net系で実装出来ないか試行錯誤したのでメモを書きます。

IsAllTrueの実装

例: Pythonの実装

IsAllTrue.py
def IsAllTrue(boolList)
    return all(boolList) # 本来はこのまま呼び出し元に書ける

C#の場合

list.All(b => b)で実装出来る。(ちゃんと確認します)

IsAllTrue.cs
bool IsAllTrue(List<bool> boolList){
    return boolList.All(b => b)
}

VB.netの場合

list.All(Function(Boolean b) b)で実装出来る。

IsAllTrue.vb
Function Boolean IsAllTrue(List(Of Boolean) boolList)
    Return boolList.All(Function(Boolean b) b)
End Function

IsDictAllTrueの実装

基本的には、一旦valuesを取り出すことになります。

ただし、keysの取り出しが必要な場合、.Net系の方が強みを持ちます。

(取り出し方は要調査)

例: Pythonの実装

IsDictAllTrue.py
def IsDictAllTrue(boolDict)
    boolList = boolDict.values()
    return all(boolList) # 本来はこのまま呼び出し元に書ける

C#の場合

IsDictAllTrue.cs
bool IsDictAllTrue(List<string, bool> boolDict){
    var boolList = boolDict.Values
    return boolList.All(b => b)
}

VB.netの場合

IsDictAllTrue.vb
Function Boolean IsAllTrue(List(Of String, Boolean) boolDict)
    Dim boolList = boolDict.Values
    Return boolList.All(Function(Boolean b) b)
End Function
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2