请教高手 如何将这一小段 代码 改写成 c# 代码 跪求
请教高手 点指 把下面这段代码 改写成 C#
Public Shared Sub ChangeDataGridViewColumnName(ByVal cols As DataGridViewColumnCollection, _
ByVal ColNames As Object, ByVal NewColNames As Object)
For Each p As System.Reflection.PropertyInfo In ColNames.GetType.GetProperties
Try
Dim Value As String = p.GetValue(ColNames, Nothing)
If cols.Contains(Value) Then
cols(Value).Name = getPropertyInfo(NewColNames, p.Name).GetValue(NewColNames, Nothing)
End If
Catch ex As Exception
End Try
Next
End Sub
其中cols(Value).Name 这一段该如何改写
------解决方案--------------------cols[Value].Name = getPropertyInfo(NewColNames, p.Name).GetValue(NewColNames, null);
------解决方案--------------------这个让机器去做
------解决方案--------------------ColNames.GetType.GetProperties.ForEach(f=>{
var value=f.GetValue(ColNames, Nothing);
if(cols.Contains(value))
{
cols[value].Name = getPropertyInfo(NewColNames, p.Name).GetValue(NewColNames, Nothing)
}
})