The purpose and description of C # generic classes

Source: Internet
Author: User

Class Program
{
public class Test<t, s>
{
The type parameters of a generic class are available for class members
private T name;
Private S age;
Public Test (T-Name, S-age)
{
THIS.name = name;
This.age = age;
}
public void SetValue ()
{
Console.WriteLine (name. ToString ());
Console.WriteLine (age. ToString ());
Console.read ();
}
}
static void Main (string[] args)
{
test<string, int> t = new test<string, int> ("Xiaojun", 27);
T.setvalue ();

}
Note: (1) in the inheritance of a generic class, the type parameter of the parent class has been instantiated, in which case the subclass must not necessarily be a generic class;
(2) The type parameter of the parent class is not instantiated, but is derived from the subclass, that is, the parent and child classes are generic classes, and both have the same type parameters

The purpose and description of C # generic classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.