[nem-pl] troche javizacji do csharpizacji ?

Kamil Skalski nazgul at omega.pl
Thu Feb 5 14:49:16 CET 2004


Thursday 05 of February 2004 14:37, Lukasz Kaiser wrote:
> Hej.
>
> Wyszla Java 1.5 beta z genericsami i innymi cukierkami i pomyslalem, ze
> moze chcemy tez jakies cukierki. Jednym z mozliwych cukierkow byloby
> wzbogacenie makra "for" o obsluge iteratorow, w.g. opisu:

Trza zobaczyć.

>
> Enhanced for loop
>
> The Iterator class is used heavily by the Collections API. It provides the
> mechanism to navigate sequentially through a Collection. The new enhanced
> for loop can replace the iterator when simply traversing through a
> Collection as follows. The compiler generates the looping code necessary
> and with generic types no additional casting is required.
>
> Before
>
>    ArrayList<Integer> list = new ArrayList<Integer>();
>   for (Iterator i = list.iterator(); i.hasNext();) {
>          Integer value=(Integer)i.next();
>     }
>
>
> After
>
>     ArrayList<Integer> list = new ArrayList<Integer>();
>      for (Integer i : list) { ... }
>

A patrzyłeś na nasze (nie jest to jeszcze to co byśmy chcieli, bo nie mamy 
properties i nie możemy być zgodniz API .Netu) i C#-owe 'foreach'?

def l = array [1, 2, 3, 4, 5, 6];
foreach (x : int in l)   ( : int może być inferowane)
  printf ("%d\n", x);

w C#
foreach (int x in l)
  System.Console.WriteLine ("{0}", x)

to znaczy to wszystko działa na klasach posiadających Enumerator (z 
IEnumerator) - nie jestem pewien, czy akurat array go ma ;-)






More information about the devel-pl mailing list