Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
GeneralRe: Logout problem Pin
Heath Stewart3-Jun-04 16:58
protectorHeath Stewart3-Jun-04 16:58 
GeneralRe: Logout problem Pin
IamADotNetGuy4-Jun-04 3:55
IamADotNetGuy4-Jun-04 3:55 
GeneralRe: Logout problem Pin
Heath Stewart4-Jun-04 4:15
protectorHeath Stewart4-Jun-04 4:15 
QuestionHow to call an external program Pin
tcole3125-May-04 6:04
tcole3125-May-04 6:04 
AnswerRe: How to call an external program Pin
Colin Angus Mackay25-May-04 6:29
Colin Angus Mackay25-May-04 6:29 
GeneralRe: How to call an external program Pin
tcole3125-May-04 7:07
tcole3125-May-04 7:07 
QuestionHow to get items out of a Scripting.Dictionary instance ? Pin
PeteV25-May-04 5:07
PeteV25-May-04 5:07 
AnswerRe: How to get items out of a Scripting.Dictionary instance ? Pin
Heath Stewart25-May-04 6:38
protectorHeath Stewart25-May-04 6:38 
The Scripting.Dictionary has nothing to do with the .NET FCL, so it doesn't implement IDictionary. It is an RCW (Runtime Callable Wrapper) to a COM object and you must use the COM methods and properties it exposes. The typelib importer (tlbimp.exe) does, however, provide the GetEnumerator which enumerates over the keys, but this is only defined by the DictionaryClass (though Keys() would as well since it's actually an object[] array that you could cast to IEnumerable).

Take a look at this example code:
using System;
using Interop.Scripting;

public class Test
{
  static void Main()
  {
    IDictionary dict = new DictionaryClass();
    Add(dict, "a", 1);
    Add(dict, "b", 2);
    Add(dict, "c", 3);

    object[] keys = (object[])dict.Keys();
    for (int i=0; i<keys.Length; i++)
    {
      object key = keys[i];
      object value = dict.get_Item(ref key);
      Console.WriteLine("{0}: {1}", key, value);
    }

    object a = "a";
    Console.WriteLine("\na={0}", dict.get_Item(ref a));
  }

  static void Add(IDictionary dict, object key, object value)
  {
    dict.Add(ref key, ref value);
  }
}
The only reason I don't use a foreach loop (uses the IEnumerable implementation) is because the key variable would be read-only, which you can't use with a ref, which is required to call get_Item.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: How to get items out of a Scripting.Dictionary instance ? Pin
PeteV25-May-04 9:13
PeteV25-May-04 9:13 
GeneralRe: How to get items out of a Scripting.Dictionary instance ? Pin
Heath Stewart25-May-04 9:18
protectorHeath Stewart25-May-04 9:18 
GeneralRe: How to get items out of a Scripting.Dictionary instance ? Pin
PeteV25-May-04 9:46
PeteV25-May-04 9:46 
GeneralRe: How to get items out of a Scripting.Dictionary instance ? Pin
Heath Stewart25-May-04 10:03
protectorHeath Stewart25-May-04 10:03 
GeneralRe: How to get items out of a Scripting.Dictionary instance ? Pin
PeteV25-May-04 10:14
PeteV25-May-04 10:14 
GeneralQuestion related to Word automation Pin
Mihamar25-May-04 5:05
Mihamar25-May-04 5:05 
GeneralRe: Question related to Word automation Pin
Heath Stewart25-May-04 6:53
protectorHeath Stewart25-May-04 6:53 
GeneralRetrieve Listbox items Pin
BillAnton25-May-04 4:35
BillAnton25-May-04 4:35 
GeneralRe: Retrieve Listbox items Pin
Judah Gabriel Himango25-May-04 4:47
sponsorJudah Gabriel Himango25-May-04 4:47 
GeneralRe: Retrieve Listbox items Pin
BillAnton25-May-04 5:25
BillAnton25-May-04 5:25 
GeneralRe: Retrieve Listbox items Pin
netclectic25-May-04 5:44
netclectic25-May-04 5:44 
GeneralRe: Retrieve Listbox items Pin
BillAnton25-May-04 10:29
BillAnton25-May-04 10:29 
GeneralChange Font Size through out the application Pin
Chris#25-May-04 4:26
Chris#25-May-04 4:26 
GeneralRe: Change Font Size through out the application Pin
Judah Gabriel Himango25-May-04 4:44
sponsorJudah Gabriel Himango25-May-04 4:44 
GeneralRe: Change Font Size through out the application Pin
leppie25-May-04 9:30
leppie25-May-04 9:30 
GeneralRemoting question Pin
Judah Gabriel Himango25-May-04 4:24
sponsorJudah Gabriel Himango25-May-04 4:24 
GeneralRe: Remoting question Pin
Heath Stewart25-May-04 6:03
protectorHeath Stewart25-May-04 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.