473,225 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

Generic SortedList clashes with SortedList (namespace collision)

I seem to get name collision between the Generic collection SortedList
and C++.NET Framework collection SortedList.

How to resolve? Here are the libraries that seem to clash:
System::Collections::SortedList,
System::Collections::Generic::SortedList,
using namespace System::Collections;
using namespace System::Collections::Generic;

Below is a working version of the generic template SortedList, which
works fine, but clashes with everything in the C++.NET library
(SortedList and even Hashtable), so I cannot compile any NET
SortedList or Hashtable in the same translation unit.

RL

/////////////
// Generic Sorted List // January 29, 2007

// main project file.

// Eclass.h file

#pragma once
using namespace System;
using namespace System::Collections::Generic;
public ref class Inventory: public IComparable<Inventory^ {

public:
virtual Int32 CompareTo(Inventory^ other2);

public:
Inventory(void);
Inventory(int i);
int j;

};

//////////// Eclass.cpp
#include "StdAfx.h"
#include "EClass.h"

Inventory::Inventory():j(123){}

Inventory::Inventory(int i): j(i){}

Int32 Inventory::CompareTo(Inventory ^other2){
Int32 temp;
if (this->j == other2->j)
temp=0;
if (this->j < other2->j)
temp=1;//opposite of normal usage, ie. temp=-1; (to give
inverse sort)
if (this->j other2->j)
temp=-1; //opposite of normal usage, ie. temp=1; (to give
inverse sort)
return (temp);
}

///////////////////

/// main.cpp

#include "stdafx.h"
#include "EClass.h"
using namespace System;

int main(array<System::String ^^args)
{
Console::WriteLine(L"Hello World");
Inventory ^ myInv1 = gcnew Inventory();
Inventory ^ myInv2 = gcnew Inventory(321);
SortedList<Inventory^, int>^ sort = gcnew SortedList<Inventory^,
int>();
sort->Add(myInv1, 11); //keys, values is left to right
sort->Add(myInv2, 22);

Console::WriteLine("\n My enumerator SortedList");

IEnumerator<Inventory^^sortkeys1 = sort->Keys->GetEnumerator(); //
works! note format of IEnumerator generic class

while (sortkeys1->MoveNext()) {
Console::WriteLine("current!{0}, value!{1}, IofK {2}",sortkeys1-
>Current,sortkeys1->Current->j,sort->IndexOfKey(sortkeys1->Current));
Console::WriteLine("Value for key(i) is: {0}",sort[sortkeys1-
>Current]);
}

Console::WriteLine("\n \n Value for key(0) is: {0}, for key(1) is:
{1}",sort[myInv1],sort[myInv2]);

////////// now try reversing it!

SortedList<int, Inventory^>^ sort2 = gcnew SortedList<int,
Inventory^>();
sort2->Add(11, myInv1); //keys, values is left to right
sort2->Add(22, myInv2);

Console::WriteLine("\n my enumerator SortedList2");

IEnumerator<int^sortkeys2 = sort2->Keys->GetEnumerator(); //works!
note format of IEnumerator generic class

while (sortkeys2->MoveNext()) {
Console::WriteLine("current!{0}, IofK {1}",sortkeys2->Current,sort2-
>IndexOfKey(sortkeys2->Current));
Console::WriteLine("Value for key(i) is (hard to print):
{0}",sort2[sortkeys2->Current]);

}

Console::WriteLine("\n \n Value for key(0) is: {0}, for key(1) is:
{1}",sort2[11],sort2[22]);
return 0;
}
//////////
// output:

Hello World

By enumerator SortedList
current!Inventory, value!321, IofK 0
Value for key(i) is: 22
current!Inventory, value!123, IofK 1
Value for key(i) is: 11
Value for key(0) is: 11, for key(1) is: 22

my enumerator SortedList2
current!11, IofK 0
Value for key(i) is (hard to print): Inventory
current!22, IofK 1
Value for key(i) is (hard to print): Inventory
Value for key(0) is: Inventory, for key(1) is: Inventory
Press any key to continue . . .

Jan 30 '07 #1
1 3872
Well I finally "fixed" this by putting the two different SortedList
(s) in their own namespace, to avoid having to use a scope resolution
operator qualifier that's 30 letters long. There was a conflict
before because each was in main().

What amazes me is that MS's compilers don't recognize there are two
different classes from the declaration--the generic uses <,notation
while the standard collection does not. But so be it.

RL

On Jan 29, 5:31 pm, "raylopez99" <raylope...@yahoo.comwrote:
I seem to get name collision between the Generic collection SortedList
and C++.NET Framework collection SortedList.

How to resolve? Here are the libraries that seem to clash:
System::Collections::SortedList,
System::Collections::Generic::SortedList,
using namespace System::Collections;
using namespace System::Collections::Generic;
Jan 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: gerrod | last post by:
Hi - Does anyone know a way to created a SortedList (in the System.Collections namespace) that will sort on VALUES instead of KEYS... ? The scenario is this - I have a SortedList containing...
6
by: Jose Jarabo | last post by:
Hello, thanks in advance for any and all replies. I am not sure how to categorize this, either a bug or something else but here is my problem. I am testing with 2 elements on a sorted list. If...
5
by: Daniel Gackle | last post by:
I'm getting a strange ArgumentNullException after deserializing a SortedList. Haven't seen this discussed in the newsgroups, but it looks like a bug - unless I missed something obvious? I've...
2
by: newscorrespondent | last post by:
I have a list declared: public System.Collections.Generic.SortedList<int, System.Collections.Generic.List<MTGTracer ActiveList = new SortedList<int,List<MTGTracer>>(); The key is an integer...
2
by: Bruce Arnold | last post by:
I have a program that works fine using Remove and Add to update a value. The program processes a log file from a router and counts the hits based on url. It bothers me to use Remove/Add when all...
4
by: Oscar Thornell | last post by:
Hi, Any comments regarding this implementation... SortedList<String, Stringlist = new SortedList<String, String>(); lock (((IList)list).SyncRoot) { foreach (Object item in list) {
4
by: semedao | last post by:
Hi, I want to implement list of key-values that can be sort by 2 ways. let's say that in the first step I wanted to make SortList based on Key = int index that cannot change and Value is another...
2
by: active | last post by:
This is where a different thread ended. The subject of this query is quite different from that of the other thread so I thought I should start a new thread. I'm using Private mItemList As...
1
by: Ethan Strauss | last post by:
Hi, I have been using a variety of generic collections and I really like them, but I have just noticed something weird ... If you have a generic Dictionary (or SortedList), you can retrieve...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.