What is equivalent to Microsoft.VisualBasic.Collection in C #?

Do I have a method that takes the name of a stored procedure and Microsoft.VisualBasic.Collection ? I am referring to a vb project in which I need to pass this method to this method, but the current project I am in is in C #, so I don’t understand what can I pass to this method?

Here is the vb call:

public void CallStoredProc(string spName, Microsoft.VisualBasic.Collection params); 

In my C # application, I need to call this pass in the corresponding C # object for parameters.

+8
c #
source share
3 answers

One option is to simply use the Collection type directly from C #. This is the standard assembly type of Microsoft.VisualBasic.dll and can be used from any .Net language.

The closest collection in the standard BCL, however, is Hashtable . The conversion between Hashtable and Collection should be pretty straight forward.

for example

 using VBCollection = Microsoft.VisualBasic.Collection; ... public static VBCollection ToVBCollection(this Hashtable table) { var collection = new VBCollection(); foreach (var pair in table) { // Note: The Add method in collection takes value then key. collection.Add(pair.Value, pair.Key); } return collection; } 

Note. However, this is not a direct mapping. The Collection type supports a number of operations that the Hashtable does not like: before and after values, an index by number or key, etc. My approach would be to consistently use one type throughout the application and change either C # or the VB project accordingly

+11
source share

If you cannot change the method so that it accepts ICollection , IEnumerable or their common variants, you must pass an instance of Microsoft.VisualBasic.Collection to this instance.

From the point of view of C #, Microsoft.VisualBasic.Collection is just a class, and you can work with it as with any other class, that is, an instance of it:

 new Microsoft.VisualBasic.Collection() 

Of course, you must reference the Microsoft.VisualBasic.dll assembly in your project.

+5
source share

There is no such thing as a “C # object” or “VisualBasic.net object” - that’s all .net, so you can just include the link to Microsoft.VisualBasic.dll and use this Microsoft.VisualBasic. Collection.

C # developers are often unhappy with Microsoft.VisualBasic.dll because of the name, but you will not eat Velociraptors if you use it since .net is correct and completely language-independent.

+2
source share

All Articles