Tried to make a custom HashMap class but im stuck with GetEnumerator.
When i hover over 'test.entrySet()' this shows up
'foreach statement cannot operate on variables of type 'Project.Map' does not contain a public definition for 'GetEnumerator''
My foreach loop looks like this
foreach(Map<string, object> e in test.entrySet()) {
}
My HashMap class looks like this
public class HashMap<K, V> {
private List<object> k = new List<object>();
private List<object> v = new List<object>();
public void put(object k, object v) {
this.k.Add(k);
this.v.Add(v);
}
public object get(object k) {
var i = 0;
foreach (var key in this.k) {
if (k.Equals(key)) {
return this.v.ElementAt(i);
}
i++;
}
return null;
}
public bool exist(object k) {
return this.k.Contains(k);
}
public void clear() {
this.k.Clear();
this.v.Clear();
}
public Map entrySet() {
return null;
}
}
My Map class looks like. I think this class is useless...
public class Map<K,V> {
private List<object> k = new List<object>();
private List<object> v = new List<object>();
public Map(List<object> k, List<object> v) {
this.k = k;
this.v = v;
}
public object getKey() {
return null;
}
public object getValue() {
return null;
}
}
If someone could help me fix this code/give some tips i would be verry glad.
Should look somthing like this
HashMap<string, object test = new HashMap<string, object>();
foreach(Map<string, object> e in test.entrySet()) {
string key = e.getKey();
string value = e.getValue();
}