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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:51:12+00:00 2026-06-06T16:51:12+00:00

I need to learn how to convert type to Class in C#. In my

  • 0

I need to learn how to convert type to Class in C#.

In my case, I have an double array object but they are stored in object array.

public object Convert(object[] values, Type targetType, object parameter,
                      CultureInfo culture)
{
    if (values == null || values.Any(v => v == DependencyProperty.UnsetValue))
        return false;
    var typeOfArray = values[0].GetType();
    var firstItem = (double)values[0];
    return values.Skip(1).Any(item => (double)item == firstItem);
}

I want to make this generic implementation for any type but equals(method and operator)
doesn’t work.
But if I convert type to class I think I can do what I want.

But I want to learn ideas and how should I do this operation or How can I convert type object to Class to use it conversion operation?

  • 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-06T16:51:13+00:00Added an answer on June 6, 2026 at 4:51 pm

    I want to make this generic implementation for any type but equals(method and operator) doesn’t work.

    Three options;

    1: use the object.Equals(x,y) method (this uses the virtual Equals(x) method, but avoids a null-ref problem)

    object firstItem = values[0];
    return values.Skip(1).Any(item => Equals(item,firstItem));
    

    2: use dynamic, but realise this may impact performance:

    dynamic firstItem = values[0];
    return values.Skip(1).Any(item => (dynamic)item == firstItem);
    

    3: use generics (here, values is a typed, T[]):

    var comparer = EqualityComparer<T>.Default;
    T firstItem = values[0];
    return values.Skip(1).Any(item => comparer.Equals(item,firstItem));
    

    The nice thing about the generics option is that you avoid the need to box when it is a value-type (such as double).

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

Sidebar

Related Questions

I need to learn RegEx but don't have time to figure this out right
I have an ArrayList of Path values. I need to convert it into String
I need to learn couchbd and have been going through tutorials on views. I
I can do a few things with PowerPoint, but I need to learn more
I'm quite new to Zend & JSON, however I have the need to learn.
I have a traditional RDBMS based PHP app that I need to convert over
I need to learn more about creating setup projects from within Visual Studio to
I need to learn C++ in order to learn building Nokia WRT and or
Do I need to learn the WCF Service trace viewer tool? I understand I
Do i need to learn Java for running hadoop in Amazon EC2? I am

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.