Class with symbol [modified]
-
Hello, Recently I came up with seeing a class some thing like this
public class Stack<T> : IEnumerable<T>, ICollection, IEnumerable
{
}Could any one tell me what is <T> means ? Why it has to be given like this ? Any ideas ? -- modified at 6:50 Tuesday 2nd October, 2007 HTML tag next to class was not visible
-
Hello, Recently I came up with seeing a class some thing like this
public class Stack<T> : IEnumerable<T>, ICollection, IEnumerable
{
}Could any one tell me what is <T> means ? Why it has to be given like this ? Any ideas ? -- modified at 6:50 Tuesday 2nd October, 2007 HTML tag next to class was not visible
The reason I despair for the future of this industry, is the large number of people who are scared of google. The Stack class impliments three interfaces. It does this so that differing objects can share a common interface, when used for the same purpose.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
The reason I despair for the future of this industry, is the large number of people who are scared of google. The Stack class impliments three interfaces. It does this so that differing objects can share a common interface, when used for the same purpose.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
I think what Navaneeth tried to ask is, why is the Stack class implementing the IEnumerable Interface twice?!? Honestly I dont know either...
-
I think what Navaneeth tried to ask is, why is the Stack class implementing the IEnumerable Interface twice?!? Honestly I dont know either...
-
The reason I despair for the future of this industry, is the large number of people who are scared of google. The Stack class impliments three interfaces. It does this so that differing objects can share a common interface, when used for the same purpose.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Christian Graus wrote:
The Stack class impliments three interfaces. It does this so that differing objects can share a common interface, when used for the same purpose.
You are mistaken me, I am not asking anything related to stack class. I was asking why <T> is used after class name ?
-
Christian Graus wrote:
The Stack class impliments three interfaces. It does this so that differing objects can share a common interface, when used for the same purpose.
You are mistaken me, I am not asking anything related to stack class. I was asking why <T> is used after class name ?
Because you can use it with a generic. It's one of those new fangled .NET 2 things that's only been around since 2005 - I'm not surprised you haven't heard of it.
Deja View - the feeling that you've seen this post before.
-
Because you can use it with a generic. It's one of those new fangled .NET 2 things that's only been around since 2005 - I'm not surprised you haven't heard of it.
Deja View - the feeling that you've seen this post before.
Pete O`Hanlon wrote:
Because you can use it with a generic
Thanks, But I am not clear on this ? What do you mean ? And what will be difference like giving normal class declaration ?
-
Hello, Recently I came up with seeing a class some thing like this
public class Stack<T> : IEnumerable<T>, ICollection, IEnumerable
{
}Could any one tell me what is <T> means ? Why it has to be given like this ? Any ideas ? -- modified at 6:50 Tuesday 2nd October, 2007 HTML tag next to class was not visible
Clearer now. You are missing <T> at the first IEnumerable. Google for Generics, its "new" feature in C# 2.0
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - RĂ¼diger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe -
Clearer now. You are missing <T> at the first IEnumerable. Google for Generics, its "new" feature in C# 2.0
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - RĂ¼diger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfednh wrote:
Google for Generics, its "new" feature in C# 2.0
Thanks. Now it's becoming clearer
-
Pete O`Hanlon wrote:
Because you can use it with a generic
Thanks, But I am not clear on this ? What do you mean ? And what will be difference like giving normal class declaration ?
It means that you can use the Stack class with a generic and it will use the generic IEnumerable interface. In other words, you can create a class as Stack<MyClass> and then rely on the fact that you have the IEnumerable<T> implementation to use.
Deja View - the feeling that you've seen this post before.
-
Pete O`Hanlon wrote:
Because you can use it with a generic
Thanks, But I am not clear on this ? What do you mean ? And what will be difference like giving normal class declaration ?
The <T> means you can put whatever type you want in it. The T is short for Type. For example:
Stack<int> myStackOfIntegers = new Stack<int>();
Stack<string> stackOfStrings = new Stack<string();
Stack<MyFooType> stackOfFoos = new Stack<MyFooType>();myStackOfIntegers.Push(5); // this works, because it's a stack of integers
myStackOfIntegers.Push("hello"); // Compiler error! you pushed a string on a stack of integers. This won't build.Tech, life, family, faith: Give me a visit. I'm currently blogging about: 3 years of marriage The apostle Paul, modernly speaking: Epistles of Paul Judah Himango