Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS1546
Collapse the table of content
Expand the table of content

Compiler Error CS1546

Property, indexer, or event 'property' is not supported by the language; try directly calling accessor method 'accessor'

Your code is consuming an object that has a default indexed property and tried to use the indexed syntax. To resolve this error, call the property's accessor method. For more information on indexers and properties, see Indexers (C# Programming Guide).

The following sample generates CS1546.

This code sample consists of a .cpp file, which compiles to a .dll, and a .cs file, which uses that .dll. The following code is for the .dll file, and defines a property to be accessed by the code in the .cs file.

// CPP1546.cpp
// compile with: /clr /LD
using namespace System;
public ref class MCPP
    property int Prop [int,int]
        int get( int i, int b )
            return i;

This is the C# file.

// CS1546.cs
// compile with: /r:CPP1546.dll 
using System;
public class Test
    public static void Main()
        int i = 0;
        MCPP mcpp = new MCPP();
        i = mcpp.Prop(1,1); // CS1546
        // Try the following line instead:
        // i = mcpp.get_Prop(1,1);
© 2015 Microsoft