Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions csharp-fundamentals-maps.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@

public string getValue(string key)
{

Dictionary<string , string> map = createPerson();


return string.Empty;
return map[key];


}
Expand All @@ -64,8 +66,8 @@
*/
public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
{
return false;
return dictionary.ContainsKey(isitthere);

}


Expand All @@ -78,7 +80,9 @@
*/
public int getValueOrDefault(Dictionary<string,int> dictionary, string isitthere)
{
return 0;
return dictionary.GetValueOrDefault(isitthere);



}

Expand All @@ -105,6 +109,11 @@
map.Add(96, "nice");
// Write your code below this comment...

foreach (int number in numbers)
{
results.Add(map.GetValueOrDefault(number));

Check warning on line 114 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 114 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 114 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 114 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.
}



// // ...and above this comment
Expand Down
12 changes: 9 additions & 3 deletions csharp-fundamentals-maps.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_planets = new Dictionary<string, float>();
_planets.Add("Jupiter", 5.2f);
_planets.Add("Uranus", 19.2f);
_planets.Add("Pluto", 39f);
//_planets.Add("Pluto", 39f);
_planets.Add("Mercury", 0.39f);
_planets.Add("Saturn", 9.54f);
_planets.Add("Earth", 1f);
Expand All @@ -36,7 +36,10 @@
// the planet name and the number of letters in its name
// iterate the _planets using a foreach object to load the result dictionary.


foreach (string planet in _planets.Keys)
{
result.Add(planet, planet.Length);
}

return result;
}
Expand All @@ -52,7 +55,7 @@
}
public Dictionary<string, float> OrderedPlanetsByDescending()
{
return _planets.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
return _planets.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
}
//TODO: modify the OrderedPlanetsByDescending so it is not dictionary is not doing an OrderBy but OrderByDescending

Expand All @@ -67,7 +70,10 @@

public string FurthestFromTheSun()
{
KeyValuePair<string, float> result = OrderedPlanetsByDescending().First();

return result.Key;
return string.Empty;

Check warning on line 76 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 76 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 76 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 76 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected
}
public string ClosestToTheSun()
{
Expand Down