RE: How to I Start with C# Generics?

From: Lingeshwaran Palaniappan (lipalani_at_online.microsoft.com)
Date: 08/18/04


Date: Wed, 18 Aug 2004 20:54:19 GMT

Hi,
as suggested the logical thing to do would be to try yourself.
You might find this link useful:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html
/csharp_generics.asp
--------------------
>From: anonieko@hotmail.com (Anonieko Ramos)
>Newsgroups: microsoft.public.dotnet.languages.csharp
>Subject: How to I Start with C# Generics?
>Date: 24 Jul 2004 13:23:28 -0700
>Organization: http://groups.google.com
>Lines: 77
>Message-ID: <562cba23.0407241223.67f5066d@posting.google.com>
>NNTP-Posting-Host: 68.161.38.231
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1090700609 1116 127.0.0.1 (24 Jul 2004
20:23:29 GMT)
>X-Complaints-To: groups-abuse@google.com
>NNTP-Posting-Date: Sat, 24 Jul 2004 20:23:29 +0000 (UTC)
>Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!tiscali!newsfeed1.ip.tiscali.net!proxad.net!postnews2.google.com!not-fo
r-mail
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:261009
>X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
>
>The logical thing to do is to try it yourself.
>
>>
>>
>>
>>
>
>See this example:
>-----------------------------------------------------------
>
>using System;
>using System.Collections.Generic;
>
>namespace Tests
>{
>
> public class Employee
> {
> int id;
> string name;
>
> public Employee(int anId, string aName)
> {
> this.id = anId;
> this.name = aName;
> }
>
> public int Id
> {
> get { return this.id; }
> }
>
> public string Name
> {
> get { return this.name; }
>
> set { this.name = value; }
> }
> }
>
>}
>
>
>
>namespace Tests
>{
>
> public class GenericReferenceArrayListTest {
>
> static void Main()
> {
> DateTime start = DateTime.Now;
>
> List<Employee> employees = new List<Employee>();
>
> Employee emp = new Employee(101, "Smith, Joan");
>
>
> for (int i = 0; i < 1000000; i++)
> {
> employees.Add(emp);
> }
>
> foreach (Employee e in employees)
> {
> Employee currentEmployee = e;
> }
>
> DateTime finish = DateTime.Now;
>
> System.Console.WriteLine(String.Format("Elapsed time: {0}",
>finish.Subtract(start)));
> }
>
> }
>
>}
>

--
Lingeshwaran Palaniappan, Developer Division 
This posting is provided "AS IS" with no warranties, and confers no rights.
Note: For the benefit of the community-at-large, all responses to this 
message are best directed to the newsgroup/thread from which they 
originated.  


Relevant Pages

  • Re: constructors/static methods and inheritance query
    ... public class BaseLine: IBaseLine { ... public static BaseLine Initialize(string x1, string y1, string ... public int keyLength; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Conditional Expression Testing for Nulls
    ... Classes that in turn have Students. ... public string Name ... public class Students: CollectionBase ... public int Add ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: OOP object collections
    ... public class SomeObjectCollection: List ... string ZebraName ... private System.DateTime _createDate; ... and a Employee class. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Xml serialization, arrays, XmlAnyAttribute
    ... public class Employee ... private string _firstname; ... public class EmployeeCollection: CollectionBase ... protected override void OnInsert ...
    (microsoft.public.dotnet.framework)
  • Problem with Datagrid and OOP
    ... I have two different objects Employee and SalaryType ... public int Add ... private string _code; ...
    (microsoft.public.dotnet.languages.csharp)