以下是使用DirectCast
的示例VB.NET代码。我无法将其转换为C#。
Dim arr As ArrayList
If ViewState("SelectedRecords") IsNot Nothing Then
arr = DirectCast(ViewState("SelectedRecords"), ArrayList)
Else
arr = New ArrayList()
End If
答案 0 :(得分:4)
等效的C#代码是
ArrayList arr = default(ArrayList);
if (ViewState["SelectedRecords"] != null) {
arr = (ArrayList)ViewState["SelectedRecords"];
}
else {
arr = new ArrayList();
}