Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed converting C# to VB 1

Status
Not open for further replies.

mwa

Programmer
Jul 12, 2002
507
US
My company is using a piece of software developed by another company. Their software has an API to add/remove documents from their system. They've given us a sample written in C#, and I'm in the process of converting it to VB. I'm stuck trying to understand one thing. They have the following:
Code:
List<DocAttribute> metadata = new List<DocAttribute>();
metadata.Add(new DocAttribute() { Name = "DocumentType", Value = txtDocType.Text});
metadata.Add(new DocAttribute() { Name = "SSN", Value = txtSsn.Text});

Here is what I came up with:
Code:
Dim metadata As List(Of DocAttribute) = New List(Of DocAttribute)
Dim attribute As New DocAttribute
Dim attribute2 As New DocAttribute
attribute.Name = "DocumentType"
attribute.Value = txtDocType.Text
metadata.Add(attribute)
attribute2.Name = "SSN"
attribute2.Value = txtSsn.Text
metadata.Add(attribute2)

Three lines of code vs. Nine lines of code... It works, but is there a better way to do this in VB? What would be the syntax to add the attributes on the fly, without having to dim a new attribute variable for each attribute?

Thanks in advance...

mwa
<><
 
I just figured it out... For future reference:

Code:
metadata.add (new DocAttribute() with {.name="name", .value="123"} )

A star for me!

mwa
<><
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top