Created
March 5, 2013 08:50
-
-
Save rousso/5088886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace TestGenerics | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
MyList myList = new MyList(); | |
myList.Add(1); | |
myList.Add(2); | |
myList.Add(3); | |
myList.Print(); | |
Console.WriteLine("Now the 2nd List"); | |
My2ndList my2ndList = new My2ndList(); | |
my2ndList.Add(1); | |
my2ndList.Add(2); | |
my2ndList.Add(3); | |
my2ndList.Print(); | |
} | |
} | |
public class MyList : List<int> | |
{ | |
new private void Add(int item) | |
{ | |
item *= 10; | |
base.Add(item); | |
} | |
public void Print() | |
{ | |
foreach (int item in this) | |
Console.WriteLine(item.ToString()); | |
} | |
} | |
public class My2ndList : MyList | |
{ | |
new private void Add(int item) | |
{ | |
item *= 100; | |
base.Add(item); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment