10

ie something like

typedef Dictionary<string, string> mydict;

I swear I have seen it but cannot find it

Ramon Zarazua B.
  • 7,195
  • 4
  • 22
  • 26
pm100
  • 48,078
  • 23
  • 82
  • 145
  • BTW:SO would not let me ask a nice succint question, it has to be bigger ! – pm100 May 18 '11 at 17:54
  • I don't know if it supports generic classes, but you can try the using statement. http://msdn.microsoft.com/en-us/library/sf0df423(v=vs.80).aspx – John Hoven May 18 '11 at 17:58
  • Possible duplicate of [Equivalent of typedef in C#](http://stackoverflow.com/questions/161477/equivalent-of-typedef-in-c-sharp) – StayOnTarget Jan 05 '17 at 14:48

5 Answers5

19

using MyDict = Dictionary<String, String> which is like defining a symbol which would be replaced by the compiler.

Vijay Sirigiri
  • 4,653
  • 29
  • 31
5

Sort of.

using IntList = System.Collections.Generic.List<int>;

http://arbel.net/2004/07/07/the-hidden-c-typedef/

One issue is there is no way to #include the definition.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
2

use inheritance:

public class DoubleNameValueCollection : Dictionary< string, NameValueCollection > { }

Then use as if it were a typedef:

NameValueCollection values = new NameValueCollection();
values.Add( "value1", "value2" );
DoubleNameValueCollection dblNameCol = new DoubleNameValueCollection();
dblNameCol.Add( "key1", values );

Or if you want to confuse others:

DoubleNameValueCollection dblNameCol = new DoubleNameValueCollection
    {
        { "key1", new NameValueCollection 
            {
                { "value1", "value2" }
    }}};   
guest
  • 21
  • 1
0

There is no equivalent of typedef in C#, however you could use 'using' for aliases.

Kromagg
  • 69
  • 3
0

There is delegate, which is used for defining a type of method argument,

there is using BlaBla = Full.Name.Space.Yada.Yada;

however, the using statement is only valid in current file.

Ryan T. Grimm
  • 1,307
  • 1
  • 9
  • 17
Danny Varod
  • 17,324
  • 5
  • 69
  • 111