2
Please make a code review for methods in this class and solve problems you find. Expected result: list of problems, new code including fixes
C# .NET
namespace ActumInterview
{
public class CodeReview
{
/// <summary>
/// This method returns integer parsed from the source. If parsing fails it should return zero.
/// </summary>
/// <param name="o">Object with data to parse.</param>
/// <returns>Parsed value</returns>
public int Parse(object o)
{
return int.Parse(o.ToString());
}
/// <summary>
/// This method returns concatenated string from the array of the strings.
/// </summary>
/// <param name="lines">Array of strings with lines.</param>
/// <returns>Concatenated string.</returns>
public string Concat(string[] lines)
{
string result;
for(int i = 0; i < lines.Length; i++)
{
result += lines[i];
}
return result;
}
}
}
public int Parse(object o)
{
try
{
return int.Parse(o.ToString());
}
catch (Exception Ex)
{
return 0;
}
}
Pokud by nedopadlo je ošetřena vyjímka dle zadání.
Původní neobsahuje možnou vyjímku.
-------------------------------------------------------------
string[] lines = new string[5]; //pro lepší popchopení jsem si napsal pole
static string Concat(string[] lines)
{
string result = "";
for (int i = 0; i < lines.Length; i++)
{
result += lines[i];
}
return result;
}
Hodnota string musí být alespoň "" nebo null Empty jinak je problém v debugu.
Testováno -> accepted
Neformátovaný
Přidáno: 25.5.2016
Expirace: Neuvedeno