0

I'm using .Net Framework 3.5.

I need something like a Tuple, but how I don't have it, I created my own Tuple using this

So, I have

public class Tupla<T1, T2>
        {
            public T1 First { get; private set; }
            public T2 Second { get; private set; }
            internal Tupla(T1 first, T2 second)
            {
                First = first;
                Second = second;
            }
        }

        public static class Tupla
        {
            public static Tupla<T1, T2> New<T1, T2>(T1 first, T2 second)
            {
                var tuple = new Tupla<T1, T2>(first, second);
                return tuple;
            }
        }

Then, I need to use something like a Dictionary with some other code mine. For each Key, I need to return a Tupla, filled with values.

So, I created my class

public class ParametrosMultiples : Dictionary<String, Tupla>
    {

    }

But It doesn't recognize my Tupla class. As far as I can see, I can use custom clases (and not only types, like String, Int32, etc)

The error I get is

type or namespace name 'Tupla' could not be found (are you missing a using directive or an assembly reference?)

But they are in the same namespace, even in the same .cs (I only mention that to make sure that is in the same namespace, because we use only one namespace for .cs for convention)

If I can't use that Tupla, how I can retrieve two values from a Key?

Edit:

To show how I got my class:

namespace ReportesWeb.WebApp.App_Shared
{
 public class ParametrosMultiples : Dictionary<String, Tupla<Int32, Int32>>
 {
 }

// here goes the Tupla code showed above, the two classes

}

Edit2:

I have removed the Static Tupla (leaving only One Tupla Class) and still get the same error, so is not a problem of conflict with the names

Community
  • 1
  • 1
Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82

1 Answers1

2

You need to specify the generic parameters of your Tupla class.

public class ParametrosMultiples : Dictionary<String, Tupla<type1,type2>>
{

}

Though the error you are getting seems to suggest that this class is either in a separate assembly that has not been referenced, or (if it is referenced or is in the same assembly), that you have not imported the namespace it lives in into the class that needs to use it with a using directive.

You also seem to have two separate classes (a static and a "normal" one) with the same name - Tupla. This will certainly cause a naming conflict. Consider changing the name of one of them, or incorporate the functionality into a single class.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • try `Dictionary>` but not working :/ Get same error. Not even recognize Tupla the intellisense – Gonzalo.- Aug 14 '12 at 19:19
  • @ElVieejo - Did you import the namespace? – Oded Aug 14 '12 at 19:20
  • they are in the same namespace – Gonzalo.- Aug 14 '12 at 19:20
  • @ElVieejo - The error suggests otherwise. Did you compile the assembly before trying to use the new type? – Oded Aug 14 '12 at 19:22
  • you can see hoy I got now my namespace. They are in the same file, in the same namespace – Gonzalo.- Aug 14 '12 at 19:22
  • 1
    @ElVieejo - How did you manage to have _two_ public classes called `Tupla`? And in the same namespace? – Oded Aug 14 '12 at 19:23
  • I have erased ParametrosMultiples class. Compiled (so I got the Tupla compiled). Then I create ParametrosMultiples, and not working – Gonzalo.- Aug 14 '12 at 19:24
  • even removing the Static Tupla (only leaving the other one), still not working – Gonzalo.- Aug 14 '12 at 19:31
  • @ElVieejo - I suggest taking another look at your namespaces. – Oded Aug 14 '12 at 19:32
  • They are in the same namespace, how Can I get problem of reference ? – Gonzalo.- Aug 14 '12 at 19:36
  • @ElVieejo - The error "type or namespace name 'Tupla' could not be found (are you missing a using directive or an assembly reference?)" means that either the class is not visible. Either because of accessibility or because the assembly/namespace have not been referenced/imported. – Oded Aug 14 '12 at 19:38
  • 1
    I solved it. I've shame to say the solution. It was a little "}", and VS consider that it was a method instead of a class (even if I put class, VS ignore it and compile as well). So, remove that "}" missing, and works well. Thank you, you help giving me some orientation, so I will accept your answer – Gonzalo.- Aug 14 '12 at 19:42