1

I'm porting a c++ MFC class in c# and i have a problem.

The c++ class have a

CMap<int,int,CString,CString>MapIndexNote;

How can i create the equivalent in c# ? I have read about Dictionnary and Hastables, but i have difficulty with 4 parameters.

Thanks a lot,

Nixeus

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
Walter Fabio Simoni
  • 5,671
  • 15
  • 55
  • 80

1 Answers1

3

The equivalent is Dictionary<int, string>.

Looking at the definition of CMap you can see that the 2nd and 4th types only exist to let you specify whether the 1st and 3rd types are passed by reference or by value.

C# will do the right thing semi-automatically: because all value types including int are passed by value, whereas reference types including string are passed as (reference-counted) references (however note that a 'reference' doesn't mean the same thing in C# as in C++).

Community
  • 1
  • 1
ChrisW
  • 54,973
  • 13
  • 116
  • 224
  • .NET *doesn't* use reference counting. With both value types and reference types, the value of the expression is passed by value by default. There's no need to make a distinction for argument passing - but it *is* worth noting that the value of an expression is never an object, only a value type value or a reference. (Or a pointer, of course...) – Jon Skeet Nov 11 '12 at 13:56
  • I should have said "garbage collectable" and not "reference counted". – ChrisW Nov 11 '12 at 14:55