VBA Как я могу вызвать конструктор возвращаемого класса из C # - PullRequest
0 голосов
/ 28 сентября 2018

У меня есть класс в C # с конструктором

namespace CollectionHandler
{
    public class Dict
    {
        private Scripting.Dictionary dict = new Scripting.Dictionary();

        public Dict()
        {
            dict.Add(1, "Carl Johnson");
            dict.Add(2, "Leon");
            dict.Add(3, "Claire");
            dict.Add(4, "Jill");
            dict.Add(5, "Chris");
            dict.Add(6, "Vrad");
            dict.Add(7, "Aida");
            dict.Add(8, "Ryder");
            dict.Add(9, "Snake");
        }

        public Scripting.Dictionary ReturnDict()
        {
            return dict;
        }
    }
}

в VBA, это мои коды.

Public Sub ShowDictionaries()
    Dim msg As String

    Dim pdict As Dictionary
    Set pdict = New Dictionary

    Dim x As CollectionHandler.Dict
    Set x = New CollectionHandler.Dict ' I thought this is the constructor

    Dim ctr As Long


    Dim key As Variant
    ctr = 0
    For Each key In x.ReturnDict().Keys
        ctr = ctr + 1
        pdict.Add key, x.ReturnDict()(key)
        Dim str1 As String
        str1 = "Key: " & ctr & " Value: " & pdict(ctr) & vbNewLine
        msg = msg & str1
    Next

    MsgBox msg, vbInformation, "We Are Items From C#"


End Sub

В окне сообщения пусто, так как список элементов словаря в C #находится в конструкторе, как я могу вызвать конструктор CollectionHandler.Dict?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...