BaseGet Method (Int32)
Collapse the table of content
Expand the table of content

NameObjectCollectionBase.BaseGet Method (Int32)


Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.

Namespace:   System.Collections.Specialized
Assembly:  System (in System.dll)

protected object BaseGet(
	int index


Type: System.Int32

The zero-based index of the value to get.

Return Value

Type: System.Object

An Object that represents the value of the entry at the specified index.

Exception Condition

index is outside the valid range of indexes for the collection.

This method is an O(1) operation.

The following code example uses BaseGetKey and BaseGet to get specific keys and values.

// a custom ObjRef class that outputs its status
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public class MyObjRef : ObjRef {

   // only instantiate using marshaling or deserialization
   private MyObjRef() { }

   public MyObjRef(MarshalByRefObject o, Type t) : base(o, t)  {
      Console.WriteLine("Created MyObjRef.");

   public MyObjRef(SerializationInfo i, StreamingContext c) : base(i, c) {
      Console.WriteLine("Deserialized MyObjRef.");

   public override void GetObjectData(SerializationInfo s, StreamingContext c) {
      // After calling the base method, change the type from ObjRef to MyObjRef
      base.GetObjectData(s, c);
      Console.WriteLine("Serialized MyObjRef.");

   public override Object GetRealObject(StreamingContext context) {

      if ( IsFromThisAppDomain() || IsFromThisProcess() ) {
         Console.WriteLine("Returning actual object referenced by MyObjRef.");
         return base.GetRealObject(context);
      else {
         Console.WriteLine("Returning proxy to remote object.");
         return RemotingServices.Unmarshal(this);

   public void ORDump() {

      Console.WriteLine(" --- Reporting MyObjRef Info --- ");
      Console.WriteLine("Reference to {0}.", TypeInfo.TypeName);
      Console.WriteLine("URI is {0}.", URI);
      Console.WriteLine("\nWriting EnvoyInfo: ");

      if ( EnvoyInfo != null) {

         IMessageSink EISinks = EnvoyInfo.EnvoySinks;
         while (EISinks != null) {
            Console.WriteLine("\tSink: " + EISinks.ToString());  
            EISinks = EISinks.NextSink;
         Console.WriteLine("\t {no sinks}");

      Console.WriteLine("\nWriting ChannelInfo: ");
      for (int i = 0; i < ChannelInfo.ChannelData.Length; i++)
         Console.WriteLine ("\tChannel: {0}", ChannelInfo.ChannelData[i]);
      Console.WriteLine(" ----------------------------- ");

// a class that uses MyObjRef
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public class LocalObject : MarshalByRefObject {
   // overriding CreateObjRef will allow us to return a custom ObjRef
   public override ObjRef CreateObjRef(Type t) {
      return new MyObjRef(this, t);

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft