Generic foreach loop in C#.
Posted
by mcoolbeth
on Stack Overflow
See other posts from Stack Overflow
or by mcoolbeth
Published on 2010-03-30T18:27:14Z
Indexed on
2010/03/30
18:43 UTC
Read the original article
Hit count: 624
The compiler, given the following code, tells me "Use of unassigned local variable 'x'." Any thoughts?
public delegate Y Function<X,Y>(X x);
public class Map<X,Y>
{
private Function<X,Y> F;
public Map(Function f)
{
F = f;
}
public Collection<Y> Over(Collection<X> xs){
List<Y> ys = new List<Y>();
foreach (X x in xs)
{
X x2 = x;//ys.Add(F(x));
}
return ys;
}
}
© Stack Overflow or respective owner