Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:15:10+00:00 2026-06-09T06:15:10+00:00

Due to the existing framework I am using, a method call is returning a

  • 0

Due to the existing framework I am using, a method call is returning a SortedList object. Because I wrote the other side of this call I know that it is in fact a SortedList. While I can continue to work with the SortedList, using the generic would convey my meaning better. So, how do you change the non-generic SortedList into an appropriately typed generic SortedList?

The background on this is that the call is a remote procedure call using the SoapFormatter. The SoapFormatter does not implement generics (Thank you, Microsoft). I cannot change the formatter since some non-.Net programs also use other method calls against the service.

I would like my proxy call to look like the following:

public SortedList<string, long> GetList(string parameter)
{
    return _service.GetList(parameter);
}

Where the interface for the GetList call is as follows due to the SoapFormatter requirements:

public SortedList GetList(string parameter);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:15:11+00:00Added an answer on June 9, 2026 at 6:15 am

    A conversion function for your usage:

    static SortedList<TKey,TValue> StronglyType<TKey,TValue>(SortedList list) {
        var retval = new SortedList<TKey,TValue>(list.Count);
        for(int i=0; i<list.Count; i++) 
            retval.Add((TKey)list.GetKey(i), (TValue)list.GetByIndex(i));
        return retval;
    }
    

    The equivalent foreach(DictionaryEntry entry in list) approach is slightly slower due to the implicit cast to unbox the DictionaryEntry (you always need the casts to TKey/TValue).

    Ballpark performance overhead: On my years old machine here, this function takes 100ms to convert a 1000 lists with 1000 entries each.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question may seem odd due to new existing alternatives, but trust
Say for example, using javascript i would normally call a method like this <a
I have an existing .NET 3.5 based framework that is extended using custom plugins.
Due to a sad situation I receive HTML like this: <p>Perform the following commands:
Due to the lack of documentation for this on MSDN, I am forced to
Due to weird domain/subdomain cookie issues that I'm getting, I'd like to know how
I am trying to migrate existing code that uses XmlSerializer to protobuf-net due to
I have an existing app in which I added the json-framework. Now it won't
Using Visual Studio 2010, when I add the four IronRuby references to an existing
I am writing an excel report using an action,controller, servlet struts framework. The report

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.