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 8938245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:34:54+00:00 2026-06-15T10:34:54+00:00

So I was looking at the MSDN example here: Constraints on Type Parameters (C#

  • 0

So I was looking at the MSDN example here: Constraints on Type Parameters (C# Programming Guide) and the 1st example shows the following generic class defining a where constraint with a single concrete type: Employee

public class GenericList<T> where T : Employee

Now when using a where constraint I totally understand the use when defining > 1 type, or most certainly when using an Interface. However (and I know it was only an example), why would I ever want to just use a where constraint to restrict to a single concrete type? Couldn’t I just replace the code below:

public T FindFirstOccurrence(string s)

with the following since there is only a single constraint anyway?

public Employee FindFirstOccurrence(string s)

The only reason I could see deploying code with a single where constriant is for flexibility in the future to add additional constraints for if Employee became IEmployee and I was set up a bit easier for the changes.

Can someone explain what purpose using a where constraint for a single type provides?

Thanks!

  • 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-15T10:34:55+00:00Added an answer on June 15, 2026 at 10:34 am

    why would I ever want to just use a where constraint to restrict to a single concrete type?

    Not quite right there – the constraint is on the Employee type and any type that inherits from it, so it can apply to Manager and CEO classes as well.

    Defining the constraint means you can use any accessible methods on the Employee type inside your code, whether the passes in type is an Employee or an inheriting type.

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

Sidebar

Related Questions

I'm looking at the TPL exception handling example from MSDN @ http://msdn.microsoft.com/en-us/library/dd537614(v=VS.100).aspx The basic
I am extremely new to Direct2D after just looking at the MSDN start guide
MSDN has the functionality I'm looking for here . Since microsoft recognizes the usefulness
I've been looking into the Timer class ( http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx ), but the thing about
Looking at this example of named pipes using Overlapped I/O from MSDN, I am
I'm looking for an example scenario where this function could be used. MSDN documentation
I was looking at Example 2 on this msdn page about Thread synchronization with
Looking at MSDN documentaion for GetTokenInformation() and the Getting the Logon SID example, GetTokenInformation()
I was looking at these examples on Microsoft.com here: http://support.microsoft.com/kb/316005 http://msdn.microsoft.com/en-us/library/aa225754%28v=sql.80%29.aspx But it's saying
I'm looking at the MSDN subscription comparison ( http://msdn.microsoft.com/en-us/subscriptions/subscriptionschart.aspx ) and am a bit

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.