-2

I have recently come across some code where a class is written specifying a type:

  public class MyClass<T>
   {

   }

OR

Public Class MyClass(Of T)

End Class

I don't understand the purpose?

I read the MSDN explanations of a class statement but still not quite sure why this would be used?

Anyone with a good explanation?

Culpepper
  • 1,093
  • 12
  • 19
  • 2
    https://msdn.microsoft.com/en-us/library/ms379564%28v=vs.80%29.aspx – PM 77-1 May 20 '15 at 05:11
  • Just a one hint to you That's called Template in C++ and generics in Java and c#. I would suggest you to have some tutorial on this. – Jenish Rabadiya May 20 '15 at 05:12
  • http://stackoverflow.com/questions/3358416/generic-classes-t-specifying-from-a-range-of-types-vb-net – Tharif May 20 '15 at 05:14
  • 1
    @JenishRabadiya: You can't compare C++ Templates and Generics in Java and C#. They might look the same but they do work completly different. You have specialication, partial specialication and so on. Detailed answer here: http://stackoverflow.com/questions/31693/what-are-the-differences-between-generics-in-c-sharp-and-java-and-templates-i – ckruczek May 20 '15 at 05:15
  • @ckruczek Thanks for the information but here I was just meant that these sort of things refer to these terminology rather than in depth thing that run-time does for us differently for various programming languages. – Jenish Rabadiya May 20 '15 at 05:24
  • @JenishRabadiya: Agreed on that! :) – ckruczek May 20 '15 at 05:25

1 Answers1

1

Well thats called Generics. The meaning of such kind of class is,that you can provide some typeinformation when instantiating the class. A very popular example is the class List<T>. Where you can specify the type that is beeing saved into the list. Example:

List<int> ints = new List<int>(); List<String> strings = new List<String>;

ckruczek
  • 2,361
  • 2
  • 20
  • 23