Question

Je n'ai pas beaucoup de fond en ce qui concerne le com ni les coclasses, donc je ne comprends pas très bien pourquoi je peux utiliser le new opérateur avec une interface. D'après une vision de langue / framework-agnostique, il est déroutant pourquoi cela compile et s'exécute correctement:

using Microsoft.Office.Interop.Excel;

public class ExcelProgram
{
    static void Main(string[] args)
    {
        Application excel = new Application();
    }
}

Inspection Application Dans Visual Studio 2010 me montre:

using System.Runtime.InteropServices;

namespace Microsoft.Office.Interop.Excel
{
    // Summary:
    //     Represents the entire Microsoft Excel application.
    [Guid("000208D5-0000-0000-C000-000000000046")]
    [CoClass(typeof(ApplicationClass))]
    public interface Application : _Application, AppEvents_Event
    {
    }
}

Que se passe-t-il dans les coulisses?

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top