比如说我转到 stack<> 的定义
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;namespace System.Collections.Generic
{
// 摘要:
// Represents a variable size last-in-first-out (LIFO) collection of instances
// of the same arbitrary type.
//
// 类型参数:
// T:
// Specifies the type of elements in the stack.
[Serializable]
[ComVisible(false)]
[DebuggerDisplay("Count = {Count}")]
public class Stack<T> : IEnumerable<T>, ICollection, IEnumerable
{
// 摘要:
// Initializes a new instance of the System.Collections.Generic.Stack<T> class
// that is empty and has the default initial capacity.
public Stack();
//
// 摘要:
// Initializes a new instance of the System.Collections.Generic.Stack<T> class
// that contains elements copied from the specified collection and has sufficient
// capacity to accommodate the number of elements copied.
//
// 参数:
// collection:
// The collection to copy elements from.
//
// 异常:
// System.ArgumentNullException:
// collection is null.
public Stack(IEnumerable<T> collection);
//
// 摘要:
// Initializes a new instance of the System.Collections.Generic.Stack<T> class
// that is empty and has the specified initial capacity or the default initial
// capacity, whichever is greater.
//
// 参数:
// capacity:
// The initial number of elements that the System.Collections.Generic.Stack<T>
// can contain.
//
// 异常:
// System.ArgumentOutOfRangeException:
// capacity is less than zero.
public Stack(int capacity); // 摘要:
// Gets the number of elements contained in the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// The number of elements contained in the System.Collections.Generic.Stack<T>.
public int Count { get; } // 摘要:
// Removes all objects from the System.Collections.Generic.Stack<T>.
public void Clear();
//
// 摘要:
// Determines whether an element is in the System.Collections.Generic.Stack<T>.
//
// 参数:
// item:
// The object to locate in the System.Collections.Generic.Stack<T>. The value
// can be null for reference types.
//
// 返回结果:
// true if item is found in the System.Collections.Generic.Stack<T>; otherwise,
// false.
public bool Contains(T item);
//
// 摘要:
// Copies the System.Collections.Generic.Stack<T> to an existing one-dimensional
// System.Array, starting at the specified array index.
//
// 参数:
// array:
// The one-dimensional System.Array that is the destination of the elements
// copied from System.Collections.Generic.Stack<T>. The System.Array must have
// zero-based indexing.
//
// arrayIndex:
// The zero-based index in array at which copying begins.
//
// 异常:
// System.ArgumentNullException:
// array is null.
//
// System.ArgumentOutOfRangeException:
// arrayIndex is less than zero.
//
// System.ArgumentException:
// arrayIndex is equal to or greater than the length of array. -or- The number
// of elements in the source System.Collections.Generic.Stack<T> is greater
// than the available space from arrayIndex to the end of the destination array.
public void CopyTo(T[] array, int arrayIndex);
//
// 摘要:
// Returns an enumerator for the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// An System.Collections.Generic.Stack<T>.Enumerator for the System.Collections.Generic.Stack<T>.
public Stack<T>.Enumerator GetEnumerator();
//
// 摘要:
// Returns the object at the top of the System.Collections.Generic.Stack<T>
// without removing it.
//
// 返回结果:
// The object at the top of the System.Collections.Generic.Stack<T>.
//
// 异常:
// System.InvalidOperationException:
// The System.Collections.Generic.Stack<T> is empty.
public T Peek();
//
// 摘要:
// Removes and returns the object at the top of the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// The object removed from the top of the System.Collections.Generic.Stack<T>.
//
// 异常:
// System.InvalidOperationException:
// The System.Collections.Generic.Stack<T> is empty.
public T Pop();
//
// 摘要:
// Inserts an object at the top of the System.Collections.Generic.Stack<T>.
//
// 参数:
// item:
// The object to push onto the System.Collections.Generic.Stack<T>. The value
// can be null for reference types.
public void Push(T item);
//
// 摘要:
// Copies the System.Collections.Generic.Stack<T> to a new array.
//
// 返回结果:
// A new array containing copies of the elements of the System.Collections.Generic.Stack<T>.
public T[] ToArray();
//
// 摘要:
// Sets the capacity to the actual number of elements in the System.Collections.Generic.Stack<T>,
// if that number is less than 90 percent of current capacity.
public void TrimExcess(); // 摘要:
// Enumerates the elements of a System.Collections.Generic.Stack<T>.
[Serializable]
public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
{ // 摘要:
// Gets the element at the current position of the enumerator.
//
// 返回结果:
// The element in the System.Collections.Generic.Stack<T> at the current position
// of the enumerator.
//
// 异常:
// System.InvalidOperationException:
// The enumerator is positioned before the first element of the collection or
// after the last element.
public T Current { get; } // 摘要:
// Releases all resources used by the System.Collections.Generic.Stack<T>.Enumerator.
public void Dispose();
//
// 摘要:
// Advances the enumerator to the next element of the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// true if the enumerator was successfully advanced to the next element; false
// if the enumerator has passed the end of the collection.
//
// 异常:
// System.InvalidOperationException:
// The collection was modified after the enumerator was created.
public bool MoveNext();
}
}
}
怎么只有申明呢 C# 不是不允许在类外实现函数的吗请问要怎么看具体代码?
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;namespace System.Collections.Generic
{
// 摘要:
// Represents a variable size last-in-first-out (LIFO) collection of instances
// of the same arbitrary type.
//
// 类型参数:
// T:
// Specifies the type of elements in the stack.
[Serializable]
[ComVisible(false)]
[DebuggerDisplay("Count = {Count}")]
public class Stack<T> : IEnumerable<T>, ICollection, IEnumerable
{
// 摘要:
// Initializes a new instance of the System.Collections.Generic.Stack<T> class
// that is empty and has the default initial capacity.
public Stack();
//
// 摘要:
// Initializes a new instance of the System.Collections.Generic.Stack<T> class
// that contains elements copied from the specified collection and has sufficient
// capacity to accommodate the number of elements copied.
//
// 参数:
// collection:
// The collection to copy elements from.
//
// 异常:
// System.ArgumentNullException:
// collection is null.
public Stack(IEnumerable<T> collection);
//
// 摘要:
// Initializes a new instance of the System.Collections.Generic.Stack<T> class
// that is empty and has the specified initial capacity or the default initial
// capacity, whichever is greater.
//
// 参数:
// capacity:
// The initial number of elements that the System.Collections.Generic.Stack<T>
// can contain.
//
// 异常:
// System.ArgumentOutOfRangeException:
// capacity is less than zero.
public Stack(int capacity); // 摘要:
// Gets the number of elements contained in the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// The number of elements contained in the System.Collections.Generic.Stack<T>.
public int Count { get; } // 摘要:
// Removes all objects from the System.Collections.Generic.Stack<T>.
public void Clear();
//
// 摘要:
// Determines whether an element is in the System.Collections.Generic.Stack<T>.
//
// 参数:
// item:
// The object to locate in the System.Collections.Generic.Stack<T>. The value
// can be null for reference types.
//
// 返回结果:
// true if item is found in the System.Collections.Generic.Stack<T>; otherwise,
// false.
public bool Contains(T item);
//
// 摘要:
// Copies the System.Collections.Generic.Stack<T> to an existing one-dimensional
// System.Array, starting at the specified array index.
//
// 参数:
// array:
// The one-dimensional System.Array that is the destination of the elements
// copied from System.Collections.Generic.Stack<T>. The System.Array must have
// zero-based indexing.
//
// arrayIndex:
// The zero-based index in array at which copying begins.
//
// 异常:
// System.ArgumentNullException:
// array is null.
//
// System.ArgumentOutOfRangeException:
// arrayIndex is less than zero.
//
// System.ArgumentException:
// arrayIndex is equal to or greater than the length of array. -or- The number
// of elements in the source System.Collections.Generic.Stack<T> is greater
// than the available space from arrayIndex to the end of the destination array.
public void CopyTo(T[] array, int arrayIndex);
//
// 摘要:
// Returns an enumerator for the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// An System.Collections.Generic.Stack<T>.Enumerator for the System.Collections.Generic.Stack<T>.
public Stack<T>.Enumerator GetEnumerator();
//
// 摘要:
// Returns the object at the top of the System.Collections.Generic.Stack<T>
// without removing it.
//
// 返回结果:
// The object at the top of the System.Collections.Generic.Stack<T>.
//
// 异常:
// System.InvalidOperationException:
// The System.Collections.Generic.Stack<T> is empty.
public T Peek();
//
// 摘要:
// Removes and returns the object at the top of the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// The object removed from the top of the System.Collections.Generic.Stack<T>.
//
// 异常:
// System.InvalidOperationException:
// The System.Collections.Generic.Stack<T> is empty.
public T Pop();
//
// 摘要:
// Inserts an object at the top of the System.Collections.Generic.Stack<T>.
//
// 参数:
// item:
// The object to push onto the System.Collections.Generic.Stack<T>. The value
// can be null for reference types.
public void Push(T item);
//
// 摘要:
// Copies the System.Collections.Generic.Stack<T> to a new array.
//
// 返回结果:
// A new array containing copies of the elements of the System.Collections.Generic.Stack<T>.
public T[] ToArray();
//
// 摘要:
// Sets the capacity to the actual number of elements in the System.Collections.Generic.Stack<T>,
// if that number is less than 90 percent of current capacity.
public void TrimExcess(); // 摘要:
// Enumerates the elements of a System.Collections.Generic.Stack<T>.
[Serializable]
public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
{ // 摘要:
// Gets the element at the current position of the enumerator.
//
// 返回结果:
// The element in the System.Collections.Generic.Stack<T> at the current position
// of the enumerator.
//
// 异常:
// System.InvalidOperationException:
// The enumerator is positioned before the first element of the collection or
// after the last element.
public T Current { get; } // 摘要:
// Releases all resources used by the System.Collections.Generic.Stack<T>.Enumerator.
public void Dispose();
//
// 摘要:
// Advances the enumerator to the next element of the System.Collections.Generic.Stack<T>.
//
// 返回结果:
// true if the enumerator was successfully advanced to the next element; false
// if the enumerator has passed the end of the collection.
//
// 异常:
// System.InvalidOperationException:
// The collection was modified after the enumerator was created.
public bool MoveNext();
}
}
}
怎么只有申明呢 C# 不是不允许在类外实现函数的吗请问要怎么看具体代码?
然后利用工具就可以看具体实现了
要看到真正的代码.可以去找个reflector或者直接用SDK里
带的ILDASM看.