4
I am working on a solution in which I must enter on the same function with a given name of a Park. The parks are implemented in a list and each park has a name. It happens that I intend and already tried to develop a function in which when researching a park the same should be returned (written) or should appear a message similar to "It was not found".
I’m working layered in C# (which is where I’m developing the app) and in DL (Data Layer) I have a dictionary of Park
, class that has on it a List of Automoveis
, and a List of ParkedAuto
which corresponds to a set of cars parked in a car park.
Here’s the method I have at DL:
public static bool DevolveParque(string fileName, string nomeParque)
{
if (File.Exists(fileName))
{
try
{
Stream stream = File.Open(fileName, FileMode.Open);
BinaryFormatter bin = new BinaryFormatter();
parques = (Dictionary<string, Park>)bin.Deserialize(stream);
stream.Close();
return true;
}
catch (IOException e)
{
Console.Write("ERRO:" + e.Message);
}
foreach (KeyValuePair<string, Park> x in parques)
{
if (parques.ContainsKey(nomeParque))
{
Console.WriteLine("Nome: " + x.Key);
}
}
}
return false;
}
If you have noticed me here, I test with a decisive instruction, (a if
), if my parks have a key that actually matches the name of the park, existing in the Parks Dictionary (static Dictionary<string, Park> parques = new Dictionary<string, Park>();
)
When debugging the program that is running finds the key (which by definition corresponds to the name of the park) but does not demonstrate the park, nor does it tell me that it was not found.
How can I change that.
Note: I am working with files (archives), they have Parks and also have several vehicles inside the parks
Thanks for the help Marcusvinicius ;)
– Vitor Ferreira
There is my mania to use cycles for and foreach ... I have to be more calm and careful
– Vitor Ferreira