Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Class with symbol [modified]

Class with symbol [modified]

Scheduled Pinned Locked Moved C#
questionhtmlcomdata-structures
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    N a v a n e e t h
    wrote on last edited by
    #1

    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


    My Website | Ask smart questions

    C D 2 Replies Last reply
    0
    • N N a v a n e e t h

      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


      My Website | Ask smart questions

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      J N 2 Replies Last reply
      0
      • C Christian Graus

        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 )

        J Offline
        J Offline
        Jens Meyer
        wrote on last edited by
        #3

        I think what Navaneeth tried to ask is, why is the Stack class implementing the IEnumerable Interface twice?!? Honestly I dont know either...

        J 1 Reply Last reply
        0
        • J Jens Meyer

          I think what Navaneeth tried to ask is, why is the Stack class implementing the IEnumerable Interface twice?!? Honestly I dont know either...

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          It probably didn't, it probably implemented IEnumerable and IEnumerable<T>

          --- How to get answers to your questions[^]

          1 Reply Last reply
          0
          • C Christian Graus

            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 )

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            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 ?


            My Website | Ask smart questions

            P 1 Reply Last reply
            0
            • N N a v a n e e t h

              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 ?


              My Website | Ask smart questions

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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.

              N 1 Reply Last reply
              0
              • P Pete OHanlon

                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.

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #7

                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 ?


                My Website | Ask smart questions

                P J 2 Replies Last reply
                0
                • N N a v a n e e t h

                  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


                  My Website | Ask smart questions

                  D Offline
                  D Offline
                  DavidNohejl
                  wrote on last edited by
                  #8

                  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

                  N 1 Reply Last reply
                  0
                  • D DavidNohejl

                    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

                    N Offline
                    N Offline
                    N a v a n e e t h
                    wrote on last edited by
                    #9

                    dnh wrote:

                    Google for Generics, its "new" feature in C# 2.0

                    Thanks. Now it's becoming clearer


                    My Website | Ask smart questions

                    1 Reply Last reply
                    0
                    • N N a v a n e e t h

                      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 ?


                      My Website | Ask smart questions

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • N N a v a n e e t h

                        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 ?


                        My Website | Ask smart questions

                        J Offline
                        J Offline
                        Judah Gabriel Himango
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups