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

  • SEARCH
  • Home
  • 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 398351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:44:23+00:00 2026-05-12T16:44:23+00:00

The following doesn’t compile public static T Retrieve<T>(this NameValueCollection collection, String key) where T

  • 0

The following doesn’t compile

public static T Retrieve<T>(this NameValueCollection collection, String key) where T : Object
{

    if (collection.AllKeys.Contains(key))
    {
        try
        {
            val = (T)Convert.ChangeType((object)collection[key], typeof(T));
        }
        catch { }
    }

    return val;            
}

because the Constraint cannot be the object class. So is there a way to contrain T for anything that can be set to a null?

  • 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-05-12T16:44:24+00:00Added an answer on May 12, 2026 at 4:44 pm
    where T : class
    

    Your current constraint, where T : Object says “anything which is or inherits from System.Object”, which is: everything. All types, including Int32 and String, inherit from System.Object. So constraining on Object would do nothing.

    Edit: as usual, Eric shines a light on this in a far more accurate way:

    “in C# every type derives from object”. Not true! The way to correct this myth is to simply replace “derives from” with “is convertible to”, and to ignore pointer types: every non-pointer type in C# is convertible to object.

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

Sidebar

Related Questions

Following doesn't work. I need to add a , and an input param at
I'd like to know why the following doesn't work. from twisted internet import defer,
I'd like to extract arguments from instances of Inequality. Following doesn't work, any idea
Let's say we have the EntityCollection products. Then the following doesn't work: foreach (var
Given the following string variable VAR=foo bar I need it to be passed to
Is it possible to do the following. Say my boost tuple has <std::string, T>
I am trying to loop through the below shown JS object with the following
I've come across a bug/undocumented feature in IE 7, 6.5 (perhaps others?). This doesn't
I'm not an expert in ISA server, my issue is the following: var wsUri
How do you select the attribute of a root level element in jQuery? The

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.