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. generics in c#

generics in c#

Scheduled Pinned Locked Moved C#
csharp
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.
  • A Offline
    A Offline
    Ashwani_kumar
    wrote on last edited by
    #1

    what are generic in c#

    Ashwani

    A J S 3 Replies Last reply
    0
    • A Ashwani_kumar

      its a new feature in c#2.0

      Ashwani

      A Offline
      A Offline
      Ashwani_kumar
      wrote on last edited by
      #2

      it avoids object type casting

      Ashwani

      S 1 Reply Last reply
      0
      • A Ashwani_kumar

        what are generic in c#

        Ashwani

        A Offline
        A Offline
        Ashwani_kumar
        wrote on last edited by
        #3

        its a new feature in c#2.0

        Ashwani

        A 1 Reply Last reply
        0
        • A Ashwani_kumar

          what are generic in c#

          Ashwani

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

          Have a look at Wikipedia's article on generic programming[^]. It's a broad article, but still applies to C#.

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Rabbi Kadouri Meets Messiah? The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          1 Reply Last reply
          0
          • A Ashwani_kumar

            what are generic in c#

            Ashwani

            S Offline
            S Offline
            Sathesh Sakthivel
            wrote on last edited by
            #5

            The Article by Ansil Generics[^] In CP will help you.

            Regards, Satips.

            1 Reply Last reply
            0
            • A Ashwani_kumar

              it avoids object type casting

              Ashwani

              S Offline
              S Offline
              Sandeep Akhare
              wrote on last edited by
              #6

              :confused::confused::doh::doh: Whats this ? question is yours and replies are also from your side Take a look Generics are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types they store or use. A generic collection class might use a type parameter as a placeholder for the type of objects it stores; the type parameters appear as the types of its fields, and the parameter types of its methods. A generic method might use its type parameter as the type of its return value, or as the type of one of its formal parameters. The following code illustrates a simple generic class definition. Visual Basic Copy Code Public Class Generic(Of T) Public Field As T End Class C# Copy Code public class Generic { public T Field; } C++ Copy Code generic public ref class Generic { public: T Field; }; When you create an instance of a generic class, you specify the actual types to substitute for the type parameters. This establishes a new generic class, referred to as a constructed generic class, with your chosen types substituted everywhere that the type parameters appear. The result is a type-safe class tailored to your choice of types, as the following code illustrates. Visual Basic Copy Code Dim g As New Generic(Of String) g.Field = "A string" C# Copy Code Generic g = new Generic(); g.Field = "A string"; C++ Copy Code Generic^ g = gcnew Generic(); g->Field = "A string"; The following terms are used to talk about generics in the .NET Framework: A generic type definition is a class, structure, or interface declaration that functions as a template, with placeholders for the types it can contain or use. For example, the Dictionary class can contain two types: keys and values. Because it is only a template, you cannot create instances of a class, structure, or interface that is a generic type definition. Generic type parameters, or type parameters, are the placeholders in a generic type or method definition. The Dictionary generic type has two type parameters, TKey and TValue, representing the types of its keys and values. A constructed generic type, or constructed type, is the result of specifying types for the generic type parameters of a generic type definition. A generic type argument is any type that is substituted for a generic type parameter. The general term "generic type" includes both constructed types and generic type

              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