c# - What's the correct way to not update an out variable -
i've implemented tryparse
function class minmax
this:
public static bool tryparse(string s, out minmax result) { var parts = s.split(' '); if (parts.length != 2) { return false; } float min; float max; if (!float.tryparse(parts[0].trim(), out min) || !float.tryparse(parts[1].trim(), out max)) { return false; } result = new minmax(min, max); return true; }
however doesn't compile since apparently out parameter needs written. what's correct way fix this? able use function if parsing fails, parameter passed remains unchanged. guess 1 way add like:
result = result;
but line issues warning.
assuming minmax reference type, assign null it. other tryparse method work.
check out code:
string s = "12dfsq3"; int = 444; int.tryparse(s, out i); console.writeline(i);
i set 0 instead of remaining @ 444.
Comments
Post a Comment