The compiler, given the following code, tells me: "Using the 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; } }
After fixing obvious errors, it compiles for me.
public delegate Y Function<X,Y>(X x); public class Map<X,Y> { private Function<X,Y> F; public Map(Function<X,Y> f) { F = f; } public ICollection<Y> Over(ICollection<X> xs){ List<Y> ys = new List<Y>(); foreach (X x in xs) { X x2 = x;//ys.Add(F(x)); } return ys; } }
The language specification defines the foreach as the equivalent of the while , in which the loop variable is assigned to the Current property of the enumerator object. This definitely satisfies the specific assignment rules of any suitable C # compiler for this piece of code. Either you use an inappropriate compiler, or the error occurs somewhere else.
foreach
while
Current
This is: public Map(Function f)
public Map(Function f)
Must be:
public Map(Function<X,Y> f)
And this:
public Collection<Y> Over(Collection<X> xs)
public ICollection<Y> Over(ICollection<X> xs)
Or:
public List<Y> Over(Collection<X> xs)
Source: https://habr.com/ru/post/1305588/More articles:https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1305583/why-is-my-launcher-icon-smaller-when-placed-on-the-android-desktop&usg=ALkJrhhkw1mOxPftfWycFyWqi4lrTrK4HAC # Field Inheritance - inheritanceCreate multiple models from an existing database in Django - djangoMySQL phishing query - mysqlHow can I translate Linux key codes from / dev / input / event * to ASCII in Perl? - linuxPage loading in WPF - wpfSQL: SUM required for results that match the HAVING query - sqlScreen Resolution - screen-resolutionhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1305592/whats-the-best-way-to-convert-windowsdos-files-to-unix-in-batch&usg=ALkJrhieqM-kU8HXsd0zcQ-emdXNzZfhuQ# 1130 - The localhost Host is not allowed to connect to this MySQL server - mysqlAll Articles