This document is archived and information here might be outdated.  Recommended version.


Creating variables using the New keyword (ArcObjects .NET 10.4 SDK)

Creating variables using the New keyword


Summary
This topic shows how to declare and instantiate new variables by utilizing documents in the help system.

In this topic


About creating variables using the New keyword

To instantiate a new object based on an ArcObjects class, use the "New" keyword in the .NET syntax. The class and interface documents are the types of help documents in the ArcObjects namespace reference that provide the necessary information to accomplish this task.

Class documents  

In the ArcObjects namespace reference, each class has a help document. These documents detail the name of the class, library to which the class belongs (for example, ArcMapUI, Carto, Server, and so on), platforms on which the class is supported, and all interfaces used.
In the class document, note specifically the name of the class in the title and any interfaces used. The name of the class is the variable instantiation and the interface is the variable declaration.
For example, to create an AddDataDialog object, navigate to the AddDataDialogClass help document and use the title and interfaces to generate the code. See the following screen shot and code example that shows the New keyword:  
[VB.NET]
Public Class Class2
    
    Public Sub Test()
        
        Dim addDataDialog As IAddDataDialog=New AddDataDialogClass
        
    End Sub
    
End Class
[C#]
public class Class2
{
    public void test()
    {
        IAddDataDialog addDataDialog=new AddDataDialogClass();
    }
}
If multiple interfaces are available in the class help document, choose the one that best suits your programming needs. Click an interface's link to view its properties, methods, and events.

Interface documents

Interface documents contain the following information that complements the class help documents:
The name of the interface is the variable declaration and the class is the variable instantiation.
For example, to create an AddDataDialog object with the IAddDataDialog interface displayed in the reading pane, translates into the .NET code. See the following screen shot and code example that shows the New keyword:
[VB.NET]
Public Class Class2
    
    Public Sub Test()
        
        Dim addDataDialog As IAddDataDialog=New AddDataDialogClass
        
    End Sub
    
End Class
[C#]
public class Class2
{
    public void test()
    {
        IAddDataDialog addDataDialog=new AddDataDialogClass();
    }
}


See Also:

Understanding the ArcObjects namespace reference




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine