tags:

views:

86

answers:

5

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?'
    ModelOrder = CInt(DataModel.Config.DefaultView.Item(DataModel.Config.DefaultView.Count - 1)(Common.ProfileConfigs.COLUMN_MODEL_ORDER)) + 1
End If
+1  A: 

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

Meta-Knight
What is the constant doing?
rick schott
It contains the order column's ColumnName.
Meta-Knight
A: 

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.

Dave Swersky
A: 

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
John Boker
I think in C# you would do: DataModel.Config.DefaultView[DataModel.Config.DefaultView.Count - 1][Common.ProfileConfigs.COLUMN_MODEL_ORDER]
Meta-Knight
Item can only be used in VB and is actually a property with a parameter.
Meta-Knight
+3  A: 
  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.

Martin
+1  A: 

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;
}
rick schott