Hello, athletes and champions ! ))

Please tell me - what's wrong here -

public class LinkedSet<T> : ISet<T>  
    {
        public LinkedListElement<T> Root; 
        public LinkedListElement<T> Focus; 
        public class LinkedListElement[B][U]<T>[/U][/B]
        {
            public LinkedListElement(T value)
            {
                this.Value = value;
            } 
            public T Value;
            public LinkedListElement<T> NextElement;
            public LinkedListElement<T> PreviousElement;
        }
}
 [B]Warning	1	Type parameter 'T' has the same name as the type parameter from outer type 'MyFirstsGenerics.LinkedSet<T>'[/B]

thank you for your answers)

Edited 5 Years Ago by vedro-compota: n/a

You are creating a class within another and when you do this the outer parameter is also in scope of inner class and its parameters and as we know 2 variables with one name can not be defined with in same scope because of the naming conventions and clashes

Comments

T value either inner or outer rename it... look at line number 7 and 9 first you are receiving value and putting this.value=value then again in line number 9 you declaring it public T value

Edited 5 Years Ago by abelLazm: n/a

mmm......rename type? but is there one more generic specification except T?
abelLazm, please change at least one line.

Edited 5 Years Ago by vedro-compota: n/a

is there one more generic specification except T?

T is just a place holder! you can change it anything that you want.

public class LinkedSet<T> : ISet<T>  
    {
        public LinkedListElement<T> Root;
        public LinkedListElement<T> Focus;
        public class LinkedListElement<U>
        {
//Below, use T instead if you mean this is a outer type(Then you need to change the the type of [B]Value[/B] too to T)
            public LinkedListElement(U value)
            {
                this.Value = value;
            }
            public U Value;
            public LinkedListElement<Roopesh> NextElement;
            public LinkedListElement<Roopesh> PreviousElement;
        }
    }
Comments
+++++

mmm......rename type? but is there one more generic specification except T?
abelLazm, please change at least one line.

I couldn't understand? Now look at Knvn he just wrote what i was explaining to you don't use same name in one scope.

Edited 5 Years Ago by abelLazm: n/a

as I understand from your posts - if it's necessary to use different types - It'll be correct to use different signature - T and one more ) but I don't understand - were it'll be naming conflict if i'll use only T in all cases? ))

putting this.value=value

"this" - is an inner class...in any case...- am i right?
why -

use T instead if you mean this is a outer type(Then you need to change the the type of Value too to T)

Edited 5 Years Ago by vedro-compota: n/a

Look at the example and tell what will be the answer?

.....public func2()
{
int s=func1(90);
}
public int func1(int s)
{
int s=120;
int s=s+s;
return s;
}

Edited 5 Years Ago by abelLazm: n/a

if it's necessary to use different types - It'll be correct to use different signature - T and one more ) but I don't understand - were it'll be naming conflict if i'll use only T in all cases? ))

If you use a same name(say T) for all nested types, then....if you write the code like this

LinkedSet<int>.LinkedListElement<string> le = new LinkedSet<int>.LinkedListElement<string>("");

In, public LinkedListElement(T value) the conflict is whether this T is int or string, because both int and string refers to a place holder T

Edited 5 Years Ago by Knvn: n/a

and tell what will be the answer?

good question!))
it seems to we'll have problems here -

int s=120;
int s=s+s;
return s;

the first problem is redeclaration of "s" -

int s=120;
int s=s+s;

and the second will be in - return , where return won't know which variable should it return...am I right?)
----------------

In, public LinkedListElement(T value) the conflict is whether this T is int or string

this is clear now. thank you Knvn!

Edited 5 Years Ago by vedro-compota: n/a

That's Good if your mind is clear about the same name clash :)

Edited 5 Years Ago by abelLazm: n/a

abelLazm , Knvn i'm clear only about this -

In, public LinkedListElement(T value) the conflict is whether this T is int or string

but what about this ? - does it mean that i'm applying to outer class or not in my situation?

while the further discuss this topic - the more I doubt that there is something I understand)))

Edited 5 Years Ago by vedro-compota: n/a

does it mean that i'm applying to outer class or not in my situation?

Sorry, I didn't understand!!!

Knvn, you said -

use T instead if you mean this is a outer type

but as i know this - is an current object in which we wride code...

I mean to say, you can use T, if you want to restrict the LinkedListElement is of type LinkedSet.
for ex:
LinkedSet<int>.LinkedListElement<int> le1 = new LinkedSet<int>.LinkedListElement<int>(10);

and you cant write like this:
LinkedSet<int>.LinkedListElement<string> le1 = new LinkedSet<int>.LinkedListElement<string>("myString");

Edited 5 Years Ago by Knvn: n/a

This question has already been answered. Start a new discussion instead.