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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:49:36+00:00 2026-06-09T19:49:36+00:00

Currently working on a 2-way lookup association generic, sorted by TKey. At some point

  • 0

Currently working on a 2-way lookup association generic, sorted by TKey. At some point I hope to have access like the following:

public class Assoc<TKey, TValue>
{
     public TKey this[TValue value] { get; }
     public TValue this[TKey value] { get; }
}

But obviously when TKey == TValue this will fail. Out of curiosity, is there a conditional compile syntax to do this:

public class Assoc<TKey, TValue>
{
     [Condition(!(TKey is TValue))]
     public TKey this[TValue value] { get; }

     [Condition(!(TKey is TValue))]
     public TValue this[TKey value] { get; }

     public TKey Key(TValue value) { get; }

     public TValue Value(TKey value) { get; }
}
  • 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-09T19:49:38+00:00Added an answer on June 9, 2026 at 7:49 pm

    No, there is no conditional compiltation based on Generic types.

    Generics substitutions are performed at runtime, not compile time.

    This is one of the differences between .NET generics and C++ templates.

    Generics also don’t have the concept of specialization that C++ templates have.

    http://msdn.microsoft.com/en-us/library/c6cyy67b.aspx

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

Sidebar

Related Questions

I am currently working on a little application: The structure follows in some way
I'm currently working my way through Beginning C# Programming, and have hit a problem
I am currently working on a way to load a bunch of different NPCs
I'm currently trying to get a grip on Android development and working my way
Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data
Currently working on a VBScript to automate some of the dirty PST ingestion work
I'm currently working my way through Accelerated C++ and just came across this in
I'm currently working my way through this book: http://www1.idc.ac.il/tecs/ I'm currently on a section
I'm currently working on an alternative way to view the threads and messages. But
I'm currently working on a simple way to implement a intrusive tree structure in

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.