-2

I am working with c++ cli.

Writing "System::Collections::Generic::IList" for IList every time is difficult, makes code long and difficult to read.

It is dicussed here enter link description here

using IList = System::Collections::Generic::IList; // Didn't work.
typedef System::Collections::Generic::IList Ilist; // Didn't work also.

How can I make alias for it?

David Yaw
  • 27,383
  • 4
  • 60
  • 93
  • A typedef works fine. But this is a generic type, you have to nail down the type parameters to name the concrete type. So, say, `typedef System::Collections::Generic::IList mylist;`. You could write a template to supply the type argument, but they don't behave well in metadata. – Hans Passant Oct 11 '22 at 08:05
  • Is there some reason you can't include `using namespace System::Collections::Generic;` at the top of the code file? – Mark Benningfield Oct 17 '22 at 03:15
  • I already have that line on top my code. But it doesn’t work either. Do you have a code which works in that way? My be I am doing something wrong. – Halük Uzuner Oct 18 '22 at 04:42
  • If you can't pay attention to the details, you are going to face a lot of frustration as a software developer. Note the difference in the line you have in your question with the using directive that I showed you. – Mark Benningfield Oct 18 '22 at 07:23

2 Answers2

1

I'm not sitting at a compiler, but I'm guessing that the typedef doesn't work because IList isn't the full name of that type: The full name would be IList<some type>. You should be able to do
typedef System::Collections::Generic::IList<String^> IStringList;.

Since it doesn't look like you want to change the name of IList to something else, using namespace System::Collections::Generic; should do the trick.

David Yaw
  • 27,383
  • 4
  • 60
  • 93
-1

The code below compiled. But that is not what i am looking for. type in angle brackets can be integer, string or any class list. But in some context it works.

typedef System::Collections::Generic::IList<int>^ IintList1;
using IintList2 = System::Collections::Generic::IList<int>^;

IintList1 list1 = nullptr;
list1->Add(1);
IintList2 list2 = nullptr;
list2->Add(2);