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)

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

commented: ++++ +5

......and what should be changed in the code?

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

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

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;
        }
    }
commented: +++++ +5

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.

I couldn't understand?

one minute)

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)

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;
}

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

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!

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

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)))

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");

ok . I completely understand you now Knvn))
thank you + thank abelLazm))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.