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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:24:15+00:00 2026-06-04T13:24:15+00:00

I am trying to learn generic types and I’ve written this code: public class

  • 0

I am trying to learn generic types and I’ve written this code:

public class MyProp<TDictonary, TValor>
    {
        private List<TDictonary> MyDictionary = new List<TDictonary>();
        private List<TValor> TValue = new List<TValue>();

        public MyProp<TDictonary, TValue> Search(TDictonary dictionary)
        {
            MyProp<TDictonary, TValor> dic = new MyProp<TDictonary, TValor>();
            var test = MyDictionary.FirstOrDefault(item => item == dictionary);
            return dic;
        }

So I tried to create something like a C# Dictionary. What I tried to do was to associate TDictionary and TValue to Lists, add them to my generic type and return MyProp with its content. I also plan to add other methods like Add, Remove, etc, but if I’m not able to perform a simple search within a list I certainly won’t be able to go any further.

Does anyone know if I’m going down the right path? If not, could you point to the right path?

Thank you.

  • 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-04T13:24:16+00:00Added an answer on June 4, 2026 at 1:24 pm

    I tried to create something like a C# Dictionary

    You do know about System.Collections.Generic.Dictionary<TKey, TValue> though, right?

    Anyway, I’m not sure what your generics (or even the type) are actually meant to represent (give them clearer names!), so I cannot exactly tell you what you have to change to actually search on your dictionary.

    However there are a few hints:

    • In the method, you create an instance dic, do nothing on it and then simply return that – regardless of what you do previously.
    • You only work on the MyDictionary but completely ignore the TValue field.
    • Private fields are usually named in camelCase, i.e. starting a lower case character.
    • Naming a private field TValue is very confusing, due to the starting T. That is usually reserved for generic types only.

    It gives me this error: Error 1 Operator ‘==’ cannot be applied to operands of type ‘TDictonary’ and ‘TDictonary’

    That’s because the type is a generic type without any restrictions. So it can either be a reference type or a value type, as such the compiler cannot decide about which comparison to do for the == operator. A simple, but maybe restricting, fix would be to specify a base type that is either a value type, or a reference type:

    public class MyProp<TDictonary, TValor>
        where TDictionary : class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn about this feature of javascript I keep seeing in code,
I'm trying to learn how from this site http://msdn.microsoft.com/en-us/library/cc265158(v=vs.95).aspx but the code won't compile
I have some Java code similar to: public class Thing { private IPolicy policy;
Trying to learn a bit about PDO and is going through this tutorial .
I am trying to learn the basics of dependency injection (DI). To this end
I'm trying to learn ADO.NET from Programmers Heaven: C# School Thats the code I've
I'm trying to translate this c++/cli code to c# #pragma once #define WIN32_LEAN_AND_MEAN #include
So, I've been trying to clean up my code and learn things that I
[code] private static IOrderedEnumerable<Film> OrderBy(this IEnumerable<Film> source, Func<Film, object> order, bool desc) { if
I'm trying to learn how to thread a class (specifically a method in a

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.