0

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 by vedro-compota: n/a

3
Contributors
17
Replies
18
Views
6 Years
Discussion Span
Last Post by vedro-compota
Featured Replies
  • 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 Read More

  • 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 Read More

  • 1

    [QUOTE]is there one more generic specification except T?[/QUOTE] T is just a place holder! you can change it anything that you want. [CODE]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 … Read More

  • Look at the example and tell what will be the answer? [CODE].....public func2() { int s=func1(90); } public int func1(int s) { int s=120; int s=s+s; return s; }[/CODE] Read More

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

2

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

Votes + Comments
1

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 by abelLazm: n/a

0

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

Edited by vedro-compota: n/a

1

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;
        }
    }
Votes + Comments
+++++
0

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 by abelLazm: n/a

0

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 by vedro-compota: n/a

1

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 by abelLazm: n/a

0

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 by Knvn: n/a

0

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 by vedro-compota: n/a

1

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

Edited by abelLazm: n/a

0

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 by vedro-compota: n/a

0

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

Sorry, I didn't understand!!!

0

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

1

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 by Knvn: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.