This documentation is archived and is not being maintained.

Compiler Error C3470

Error Message

'type' : a class cannot have both an indexer (default indexed property) and an operator[]

A type cannot define both a default indexer and an operator[].


The following sample generates C3470

// C3470.cpp
// compile with: /clr
using namespace System;

ref class R {
   property int default[int] {
      int get(int i) {
         return i+1;

   int operator[](String^ s) { return Convert::ToInt32(s); }   // C3470

int main() {
   R ^ r = gcnew R;
   // return r[9] + r["32"] - 42;