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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:12:08+00:00 2026-06-10T06:12:08+00:00

Is there any built in conversion or cast between KeyValuePair<T1, T2> and Tuple<T1, T2>

  • 0

Is there any built in conversion or cast between KeyValuePair<T1, T2> and Tuple<T1, T2>?

I know this would be a trivial extension method:

public static KeyValuePair<T1, T2> ToPair<T1, T2>(this Tuple<T1, T2> source)
{
    return new KeyValuePair<T1, T2>(source.Item1, source.Item2);
}

public static Tuple<T1, T2> ToTuple<T1, T2>(this KeyValuePair<T1, T2> source)
{
    return Tuple.Create(source.Key, source.Value);
}

But since objects can be used for similar purposes (especially since KeyValuePair<> was often used in place of a 2 element Tuple<> until it’s addition to C#4.0), I was wondering if such a converter was already built into the framework?

Reason I ask is I am working with an older library (targeting .NET 3.5) that used KeyValuePair<> in many places that a Tuple might be more appropriate, and I want to use Tuple<> in the new code. so I’m trying to figure out if I can just cast or convert the return kvp values from these methods to Tuple or if I need to define my own conversion (or change the older code).

  • 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-10T06:12:10+00:00Added an answer on June 10, 2026 at 6:12 am

    There is no built-in conversion in the BCL that I’m aware of, and there’s definitely no implicit or explicit cast. I doubt they’d ever add this conversion because the types are used for different purposes.

    I think your version is fine.

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

Sidebar

Related Questions

Is there any built-in method in OpenCV ( C++ API ) to subtract two
Is there any built-in method in asp.net to convert a string to a uniqueidentifier
Are there any libraries and/or built-in utilities that can facilitate the conversion of data
i've a string like 1.00E+4 Is there any built in function to convert this
Is there any built-in support for that? And if not, is there any consensus
Is there any built in functionality that enables downloading files from FTP in .NET?
Are there any built in paging functions for IEnumberable (or a better library to
Is there any built-in function in Python3/Numpy which filters an array and returns indices
Is there any built in way in mysql in which it either inserts all
1) Is there any built-in which can tell me if a variable's contents contain

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.