rick schott
rick schott

Reputation: 21117

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

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

Upvotes: 2

Views: 195

Answers (5)

rick schott
rick schott

Reputation: 21117

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

Upvotes: 1

Martin
Martin

Reputation: 40335

  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.

Upvotes: 3

John Boker
John Boker

Reputation: 83709

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

Upvotes: 0

Dave Swersky
Dave Swersky

Reputation: 34810

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.

Upvotes: 0

Meta-Knight
Meta-Knight

Reputation: 17855

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

Upvotes: 1

Related Questions