how to translate that vb code in C#

  • Thread starter Thread starter arnold
  • Start date Start date
A

arnold

HI

I 've been trying to find the equivalent code in C# but I did not succeed.
What is the equivalent of Collection in C#?

Dim c_colNewCustomerDataRows As New Collection()
If c_colNewCustomerDataRows.Count > 0 Then
Dim drCustomers As DataSet1.CustomersRow
For Each drCustomers In c_colNewCustomerDataRows
DataSet11.Customers.Rows.Add(drCustomers)
Next
End If

Thanks
 
arnold,

You can actually use the Collection class in C#, by setting a reference
to Microsoft.VisualBasic.dll. However, I don't think that this is a good
idea.

The better object, in my opinion, is the Hashtable. This is slightly
different than the Collection class in VB, because it allows any type to be
used as a key, not just strings. However, you can not access the items
using a numeric indexer, so if that is important to you (and the keys
aren't), then use the ArrayList class.

Hope this helps.
 
It should look something like this:

Collection c_colNewCustomerDataRows = new Collection();

if(c_colNewCustomerDataRows.Count > 0)
{
foreach(DataSet1.CustomersRow drCustomers in c_colNewCustomerDataRows)
{
DataSet11.Customers.Rows.Add(drCustomers);
}
}

Hm, did I send this already or forgot it? In case of duplicate I
apologize.
 
arnold said:
HI

I 've been trying to find the equivalent code in C# but I did not succeed.
What is the equivalent of Collection in C#?

Dim c_colNewCustomerDataRows As New Collection()
If c_colNewCustomerDataRows.Count > 0 Then
Dim drCustomers As DataSet1.CustomersRow
For Each drCustomers In c_colNewCustomerDataRows
DataSet11.Customers.Rows.Add(drCustomers)
Next
End If


Collection c_colNewCustomerDataRows = new Collection();
if (c_colNewCustomerDataRows.Count > 0)
{
foreach (DataSet1.CustomersRow drCustomers In c_colNewCustomerDataRows)
DataSet11.Customers.Rows.Add(drCustomers)
}
 
You'll need a reference to the Microsoft.VisualBasic.dll for the Collection
class.
Collection c_colNewCustomerDataRows = new Collection();
if(c_colNewCustomerDataRows.Count > 0)
{
DataSet1.CustomersRow drCustomers;
foreach(drCustomers in c_colNewCustomerDataRows)
{
DataSet1.Customers.Rows.Add(drCustomers);
}
}

Since I don't have access to your objects, I haven't been able to check it.
Anyway, I think you won't need the if statement.

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
Thanks for you answer. But there is no class Collection in C# and so I
would like to use an equivalent class in C#.
I would prefer not to use a reference to the Microsoft.VisualBasic.dll

I do not know how to use neither the HashTable nor the Arraylist for my
case.
I tried to use the Hashtable but when I do :
DataSet1.CustomersRow drCustomers;
foreach(drCustomers in c_colNewCustomerDataRows)
That give an error because the 2 parameter are not the same type.
I tried so ( foreach(drCustomers in (DataRow) c_colNewCustomerDataRows) but
that doesn't accept the conversion.

Thanks
 
Back
Top