Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2006

Tip: Looking for answers? Try searching our database.

Usages of a SortedList

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Prez - 12 Jul 2006 21:56 GMT
I started writing .net code yesterday and I am grasping it well enough.

I have a few questions about SortedLists.

I am using managed C++ if that makes any difference.

Of the examples I have seen it looks like the Sorted List does not use
the ^ while other variables do use the ^.  I have used the SortedList
with the ^ and gcnew and it seems to work fine.  So the question is...
Why can I get away without using the ^ ?

My second question is whether I can type the values in the sorted list.

While it is great that the sortedlist can hold any type of data item
sometimes I want it to just hold instances of a class.  For example in
the world of C++ can I take a CMap<int, int, CMyClass, CMyClass> and
turn it into a SortedList of just CMyClass.

My third question.  Is there an easier way to get a value based upon
key from a SortedList.  I don't see a function that explicitly does it.

Here is the code I am looking at using.  Was just looking for
something easier.  Note that I am using IndexOfKey to get the index
value to use GetByIndex.  Is there a GetbyKey function?

CTemperatureItem ^ TempItem = safe_cast<CTemperatureItem
^>(m_LocationInfo->GetByIndex(m_LocationInfo->IndexOfKey(Location)));

I don't need a long drawn out explanation.  Just a quick message should

fit the bill.

Thanks!
Vinzenz Feenstra - 15 Jul 2006 11:19 GMT
Vinzenz Feenstra
ewido anti-spyware development team

Antimalware Development a.s.
a Member of Grisoft Group

Contact | vinzenz.feenstra@ewido.net  |

----------------------------------------------------------------------
Der Austausch von Nachrichten mit Antimalware Development a.s. via
E-Mail dient
ausschließlich Informationszwecken. Rechtsgeschaeftliche Erklärungen dürfen
über dieses Medium nicht ausgetauscht werden. Verfälschungen des
ursprünglichen Inhaltes dieser Nachricht bei der Datenübertragung
können nicht ausgeschlossen werden.

Correspondence with Antimalware Development a.s. via e-mail is only for
information
purposes. This medium is not to be used for
 the exchange of
legally-binding communications. The falsification of the original content
of this message in the course of data transmission cannot be excluded.
Hi Prez,

Prez schrieb:
> I started writing .net code yesterday and I am grasping it well enough.
>
[quoted text clipped - 6 lines]
> with the ^ and gcnew and it seems to work fine.  So the question is...
> Why can I get away without using the ^ ?

I don't know what exactly you mean, you need to use a (managed)
Reference to an Object. Take a look at the example I have added at the end.

> My second question is whether I can type the values in the sorted list.
>
>  While it is great that the sortedlist can hold any type of data item
> sometimes I want it to just hold instances of a class.  For example in
> the world of C++ can I take a CMap<int, int, CMyClass, CMyClass> and
> turn it into a SortedList of just CMyClass.

Use the Generic Version of SortedList ;) (Also here take a look at the
example)

> My third question.  Is there an easier way to get a value based upon
> key from a SortedList.  I don't see a function that explicitly does it.
>
>  Here is the code I am looking at using.  Was just looking for
> something easier.  Note that I am using IndexOfKey to get the index
> value to use GetByIndex.  Is there a GetbyKey function?
You may use the Indexer of the SortedList. It's like the operator[] in
C++ ;)

[snip]
using namespace System;
using namespace System::Collections;
using namespace System::Collections;

// A test structure
public ref struct Test{
    int SomeValue;
    String ^SomeString;
};

// An example for the usage of a non generic SortedList
void NonGenericUsage(){
    SortedList a_list;

    Test t;
    t.SomeString = "A non generic SortedList value";
    t.SomeValue = 1234;

    a_list.Add("Test",%t);

    Console::WriteLine(dynamic_cast<Test^>(a_list["Test"])->SomeValue);
    Console::WriteLine(dynamic_cast<Test^>(a_list["Test"])->SomeString);
}

// An example for the usage of a generic SortedList
void GenericUsage(){
    Generic::SortedList<String^,Test^> a_list;

    Test t;
    t.SomeString = "A generic SortedList<KeyType,ValueType> value";
    t.SomeValue = 4321;

    a_list.Add("Test",%t);

    Console::WriteLine(a_list["Test"]->SomeValue);
    Console::WriteLine(a_list["Test"]->SomeString);
};

int main(array<System::String ^> ^args){
    Console::WriteLine("Non generic SortedList example:\n");
    NonGenericUsage();
    Console::WriteLine("\n\nGeneric SortedList<> example:\n");
    GenericUsage();
    return 0;
}
[/snip]

Regards,

Vinzenz Feenstra
Vinzenz Feenstra - 15 Jul 2006 11:24 GMT
OOps, I've accidently added my signature from my job account. I'm sorry.

Regards,

Vinzenz Feenstra

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.