Csharp/C Sharp by API/System.Collections.Generic/Collection — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:11, 26 мая 2010
Collection.Add()
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
class MainClass
{
static void Main() {
Collection<int> numbers = new Collection<int>();
numbers.Add( 2 );
numbers.Add( 9 );
Collection<string> strings = new Collection<string>();
strings.Add( "J" );
strings.Add( "B" );
Collection< Collection<int> > colNumbers = new Collection<Collection<int>>();
colNumbers.Add( numbers );
IList<int> theNumbers = numbers;
foreach( int i in theNumbers ) {
Console.WriteLine( i );
}
}
}
extends Collection<T>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
class ConverterCollection<T> : Collection<T>
{
private Converter<T,T> convert;
public ConverterCollection(Converter<T,T> convert)
{
this.convert = convert;
}
protected override void InsertItem(int index, T item)
{
base.InsertItem(index, convert(item));
}
}
public class MainClass
{
public static void Main()
{
ConverterCollection<string> c = new ConverterCollection<string>(
delegate (string s) { return s.ToUpper(); });
c.Add("Hello");
c.Add("World!");
foreach (string s in c)
Console.WriteLine(s);
}
}
new Collection<T>()
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
class MainClass
{
static void Main() {
Collection<int> numbers = new Collection<int>();
numbers.Add( 2 );
numbers.Add( 9 );
Collection<string> strings = new Collection<string>();
strings.Add( "J" );
strings.Add( "B" );
Collection< Collection<int> > colNumbers = new Collection<Collection<int>>();
colNumbers.Add( numbers );
IList<int> theNumbers = numbers;
foreach( int i in theNumbers ) {
Console.WriteLine( i );
}
}
}