开发者

Converting some legacy VB.NET code to C#, what is it doing?

开发者 https://www.devze.com 2022-12-11 16:33 出处:网络
Reference: Public Const COLUMN_MODEL_ORDER As String = MDL_ORDER.ColumnName DataModel.Config.DefaultView is a System.Data.DataView

Reference:

Public Const COLUMN_MODEL_ORDER As String = MDL_ORDER.ColumnName

DataModel.Config.DefaultView is a System.Data.DataView

What is this doing and how can I convert it?:

Dim ModelOrder As Integer = 1
Dim DataModel As New ProfileDataModel(New DBConnection, Me.ProfileID)
If DataModel.Config.DefaultView.Count > 0 Then
    'what is this line doing?'
    ModelO开发者_Go百科rder = CInt(DataModel.Config.DefaultView.Item(DataModel.Config.DefaultView.Count - 1)(Common.ProfileConfigs.COLUMN_MODEL_ORDER)) + 1
End If


  1. Operates on the last row in the dataview
  2. Pulls the value from the field whose name is represented in MDL_ORDER.ColumnName
  3. Converts it to an integer
  4. Adds one to it.

Others have posted how to convert this specific code, however, in general if you have some vb.net that you are unsure of how to code in C# simply grab Reflector and you can decompile it and browse in either language.


It takes the value of the last row's order column, converts it to an Integer, and adds 1 to it.


I figured it out, its indexers:

if (DataModel.Config.DefaultView.Count > 0)
{
    ModelOrder = (int)DataModel.Config.DefaultView[DataModel.Config.DefaultView.Count - 1][Common.ProfileConfigs.COLUMN_MODEL_ORDER] + 1;
}


It looks like it's taking the value from last row in the DataView and the column defined by COLUMN_MODEL_ORDER and adding 1 to it.


it looks like Item is also an array, so it's accessing by index the first array then accessing by index the value of the second array

ModelOrder = Convert.ToInt32(DataModel.Config.DefaultView.Item[DataModel.Config.DefaultView.Count - 1][Common.ProfileConfigs.COLUMN_MODEL_ORDER]) + 1
0

精彩评论

暂无评论...
验证码 换一张
取 消