c# - Method containing foreach statment to have only one return -


i have following method prepared unit tests , know run for-each loop, there way rid of second return statement?

public enums.gyrstatus getstatusfortransformer(             string factorycode,              enums.technology technology,              string transformertype,             int transformersize,             string transformermodel) {    fakestandardsandsizesfictionary = new dictionary<tuple<string,                                                     enums.technology,                                                     string, int, string>, int>()     {        { tuple.create("selud", technology.cvt,"---", 0, ""), 1} };    }     foreach (var pair in fakestandardsandsizesfictionary)    {        if (pair.key.item1 == factorycode &&           pair.key.item2 == technology &&           pair.key.item3 == transformertype &&           pair.key.item4 == transformersize &&           pair.key.item5 == transformermodel)            return (enums.gyrstatus)pair.value;    }    return (enums.gyrstatus)1; // second return never used } 

you can replace

return (enums.gyrstatus)1; 

with

throw new invalidoperationexception(); 

it looks more correct semantically, assuming place should never reached.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -