110,577
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsFormsApplication17
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
X x = new X();
foreach (int i in x) // A
MessageBox.Show(i.ToString());
var y = from int i in x select i;
foreach (int i in y) // B
MessageBox.Show(i.ToString());
}
}
class X : ICollection, IEnumerable
{
public int[] A = { 1, 2, 3 };
public int[] B = { 4, 5, 6 };
#region ICollection 成员
public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
public int Count
{
get { throw new NotImplementedException(); }
}
public bool IsSynchronized
{
get { throw new NotImplementedException(); }
}
public object SyncRoot
{
get { throw new NotImplementedException(); }
}
#endregion
#region IEnumerable 成员
public IEnumerator GetEnumerator()
{
return A.GetEnumerator();
}
#endregion
#region IEnumerable 成员
IEnumerator IEnumerable.GetEnumerator()
{
return B.GetEnumerator();
}
#endregion
}
}
/*============================================================
**
** Interface: IList
**
**
** Purpose: Base interface for all Lists.
**
**
===========================================================*/
namespace System.Collections {
using System;
// An IList is an ordered collection of objects. The exact ordering
// is up to the implementation of the list, ranging from a sorted
// order to insertion order.
[System.Runtime.InteropServices.ComVisible(true)]
public interface IList : ICollection
{
// Interfaces are not serializable
// The Item property provides methods to read and edit entries in the List.
Object this[int index] {
get;
set;
}
// Adds an item to the list. The exact position in the list is
// implementation-dependent, so while ArrayList may always insert
// in the last available location, a SortedList most likely would not.
// The return value is the position the new element was inserted in.
int Add(Object value);
// Returns whether the list contains a particular item.
bool Contains(Object value);
// Removes all items from the list.
void Clear();
bool IsReadOnly
{ get; }
bool IsFixedSize
{
get;
}
// Returns the index of a particular item, if it is in the list.
// Returns -1 if the item isn't in the list.
int IndexOf(Object value);
// Inserts value into the list at position index.
// index must be non-negative and less than or equal to the
// number of elements in the list. If index equals the number
// of items in the list, then value is appended to the end.
void Insert(int index, Object value);
// Removes an item from the list.
void Remove(Object value);
// Removes the item at position index.
void RemoveAt(int index);
}
}