Recently, I am coding a c# module (previously was written in vb.net), I found that "Collection Class" did NOT exist in c# but it can be found in vb.net !!
======================================
My Computer: .NetFramework 1.1 & VS.NET 2003
======================================
And therefore I am forcing myself to use the following methods to solve the "missing class" in c#
Step 1. Under the Solution Explorer, Add Reference "Microsoft.VisualBasic"
Step 2. Under the *.cs file, Type using Microsoft.VisualBasic;
Step 3: Under the *.cs file, Type Collection m_result = new Collection;
In fact, I can NATIVELY use Collection in vb.net
Dim m_results As New Collection
This is the way I can use Collection in c#. May I ask if any experts here can give me an answer what is the "suitable" way to have Collection? or Am I correct?
Here below is one of the functions (written in VB.NET) I use Collection and "grap" the data in the DAL Layer and use it for UI Layer:
----------------------------------------------------
Public Function GetBrands() As Collection
Dim m_da As New MySqlDataAdapter
Dim m_ds As New DataSet
Dim m_data As m_BrandData
Dim m_results As New Collection
Dim m_dataRow As DataRow
Dim m_SQL As String
m_SQL = "Select * From tb_Brand order by brandName"
m_da.SelectCommand =
New MySqlCommand(m_SQL, m_conn)m_da.Fill(m_ds, "table1")
For Each m_dataRow In m_ds.Tables("table1").Rowsm_data =
New m_BrandData With m_data.brandCode =
CStr(m_dataRow.Item("brandCode")).brandName =
CStr(m_dataRow.Item("brandName")) End Withm_results.Add(m_data)
m_data =
Nothing NextGetBrands = m_results
End Function----------------------------------------------------
How may I do the same thing in C#? Do I have to use Microsoft.VisualBasic reference (that's NOT native to me"?
Please advice
Coding MamaPosted Feb 22, 2007, 12:22 PM
using
System;using System.Data;
using MySql.Data.MySqlClient;
====================================
Unless I put using Microsoft.VisualBasic;
otherwise, I cannot have the class of Collection in c#
====================================
I did try to check back all related classes in msdn.microsoft.com (at Library), I thought it might be in .NET Framework 2.0 or 3.0, well, but it is still NOT existed? ...em Strange
Please advice
Note: In C#, I cannot use some other things as well ...e.g. DateDiff() fuction, well, I can code this kind of function myself but I cannot code a Collection Class, recently I am thinking why c# missed a number of good features. I read a number of forums that emphasized the advantages of using c#...
Sherwin HamidiPosted Feb 22, 2007, 11:20 AM
I had that problem earlier, and added the following assembly references and it worked out.
using
System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;