Generic Learning 1

Source: Internet
Author: User
Code
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;

Namespace Generica
{
Public   Class Genericlist < T >
{
///   <Summary>
/// Node
///   </Summary>
Private   Class Node
{
Private Node next; // Next
Public Node next
{
Set {Next = Value ;}
Get { Return Next ;}
}
Private T date; // Included data
Public T data
{
Set {Date = Value ;}
Get { Return Date ;}
}
///   <Summary>
/// Constructor
///   </Summary>
///   <Param name = "T"> </param>
Public Node (T)
{
Next =   Null ;
Date = T;
}

}
///   <Summary>
/// Header Node
///   </Summary>
Private Node head;
///   <Summary>
/// Constructor
///   </Summary>
Public Genericlist ()
{
Head =   Null ;
}
///   <Summary>
/// Add node Information
///   </Summary>
///   <Param name = "T"> </param>
Public   Void Addhead (T)
{
Node n =   New Node (t );
N. Next = Head;
Head = N;
}
///   <Summary>
/// Implement Recursion
///   </Summary>
///   <Returns> </returns>
Public Ienumerator < T > Getenumerator ()
{
Node current = Head;
While (Current ! =   Null )
{
Yield   Return Current. Data;
Current = Current. Next;
}
}
}
Class Program
{
Static   Void Main ( String [] ARGs)
{
Genericlist < Int > List =   New Genericlist < Int > ();
For ( Int X =   0 ; X <   10 ; X ++ )
{< br> list. addhead (x);

}< br> foreach ( int I in List)
{< br> system. console. writeline (I + " " );

} console. writeline ( " \ ndone! " );
console. readkey ();
}< BR >}< br>

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.