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. template classes??????

template classes??????

Scheduled Pinned Locked Moved C#
csharplinuxquestion
6 Posts 4 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.
  • T Offline
    T Offline
    TheFLC
    wrote on last edited by
    #1

    argh, can you define template classes in c#???? Or is there an alternative that Microsoft would prefer you to use? :mad: Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.

    J J L 3 Replies Last reply
    0
    • T TheFLC

      argh, can you define template classes in c#???? Or is there an alternative that Microsoft would prefer you to use? :mad: Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.

      J Offline
      J Offline
      Joao Vaz
      wrote on last edited by
      #2

      No , you can't :(( :(( :(( With luck , next c# version will support generic programming, until then ... Cheers, Joao Vaz

      1 Reply Last reply
      0
      • T TheFLC

        argh, can you define template classes in c#???? Or is there an alternative that Microsoft would prefer you to use? :mad: Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.

        J Offline
        J Offline
        James T Johnson
        wrote on last edited by
        #3

        Templates don't exist in C#, this is coming in Version 2. There is a "trick" that'll help you get by until then.

        using System;
        using T = System.Int32;

        namespace Test
        {
        class Testing
        {
        public Testing()
        {
        Console.Writeline(typeof(T).ToString());
        }
        }
        }

        Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

        T 1 Reply Last reply
        0
        • J James T Johnson

          Templates don't exist in C#, this is coming in Version 2. There is a "trick" that'll help you get by until then.

          using System;
          using T = System.Int32;

          namespace Test
          {
          class Testing
          {
          public Testing()
          {
          Console.Writeline(typeof(T).ToString());
          }
          }
          }

          Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

          T Offline
          T Offline
          TheFLC
          wrote on last edited by
          #4

          Thanks for the response, I wanted to port a generic tree class over to C# but looks like I can't for the minute, or maybe I can. What if the class took a type of Object? class Testing { public Testing(Object arg) { m_Object = arg; } Object m_Object; } I'm very new to C#, but would this work? Also when is version 2 out??? Thanks again Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.

          J 1 Reply Last reply
          0
          • T TheFLC

            Thanks for the response, I wanted to port a generic tree class over to C# but looks like I can't for the minute, or maybe I can. What if the class took a type of Object? class Testing { public Testing(Object arg) { m_Object = arg; } Object m_Object; } I'm very new to C#, but would this work? Also when is version 2 out??? Thanks again Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.

            J Offline
            J Offline
            James T Johnson
            wrote on last edited by
            #5

            TheFLC wrote: What if the class took a type of Object? That would work, but you would have lots of casting to do (Object could be called the equivalent of void* in C). This is generally the reason that the technique I mentioned came up; while you'll have a specific class for each type of tree; you'll eliminate all casting. TheFLC wrote: Also when is version 2 out??? Not for a while, version 1.0 came out a week ago today :) My guess would be at least a year before version 2.0 comes out. James James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

            1 Reply Last reply
            0
            • T TheFLC

              argh, can you define template classes in c#???? Or is there an alternative that Microsoft would prefer you to use? :mad: Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              No, you can't. The next version of the CLR will support template classes, and so will be available to all languages that want to support it, not just c#

              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