Author Topic: List<> problem  (Read 3241 times)

lynohd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
List<> problem
« on: August 20, 2016, 12:43:54 PM »
Hi, for some reason when i wanna use a list it gives me an error message saying:
Error   CS0104   'List<>' is an ambiguous reference between 'TNet.List<T>' and 'System.Collections.Generic.List<T>'   

is there any ways to use a list with TNET imported without having to put TNet.List infront of everything?

thanks in advance

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: List<> problem
« Reply #1 on: August 20, 2016, 02:13:34 PM »
Remove "using Systems.Collections.Generic;" from the top of your file, and there won't be a conflict.

lynohd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: List<> problem
« Reply #2 on: August 20, 2016, 02:19:39 PM »
Thanks, But now it wont show up in the inspector anymore..  :-\

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: List<> problem
« Reply #3 on: August 20, 2016, 02:29:26 PM »
You can still use System.Collections.Generic.List for your inspector if you like. You just need to prefix it.
  1. public System.Collections.Generic.List<string> yourList;
Personally, I avoid using generic lists. When I need to show something in inspector, I just use an array.
  1. public string[] yourList;
Shorter code, less memory usage, identical inspector functionality.

nosyrbllewe

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 11
    • View Profile
Re: List<> problem
« Reply #4 on: August 20, 2016, 03:47:06 PM »
I personally prefer to use the System.Collections.Generic.List<>, so here is my solution.

At the top with the rest of the using statements, add:
  1. using S = System.Collections.Generic;
Now when you want to use the System List, you just type:
  1. S.List<string> myList = new S.List<string>();
It is not perfect by any means, but it is easier than typing out the full namespace every time. I just wonder why Aren has named his class in TNet List<> when in NGUI he has another one called BetterList<>. Maybe they could be consolidated into one class into part of something like "Tasharen Standard Assets"?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: List<> problem
« Reply #5 on: August 20, 2016, 04:16:39 PM »
TNet is newer and better designed than NGUI, so it takes advantage of namespaces (which were not supported by Unity at the time NGUI was first created). List<> is meant to be a replacement of the generic one, which is why I named it the same. It's still in a namespace to make it possible to use both.