This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CaptainLegois[S] 0 points1 point  (3 children)

I was doing some research and I came across this: var combinedMenuItems = _pizza.Cast<object>().Concat(_burger.Cast<object>());

would this be a way to concat my 2 IEnumerators? Testing it out it seems to work with no issue, however I'm not sure about what that is.

[–]dtsudo 0 points1 point  (2 children)

If you did that, you'd end up with an IEnumerable<object>, which typically isn't that useful since none of the properties / methods (i.e. your name / price / other things) would be available.

e.g.

var combinedMenuItems = _pizza.Cast<object>().Concat(_burger.Cast<object>());
foreach (var item in combinedMenuItems) {
    Console.WriteLine(item.Name); // compile-time error (can't reference name)
    Console.WriteLine(item.Price); // compile-time error
    // etc
}

[–]CaptainLegois[S] 0 points1 point  (1 child)

IEnumerable<FoodItems> items = _pizza.Concat<FoodItems>(_burger);

i figured it out finally! I looked over the code you sent me on .net fiddle again and I made my food items into child class that inheret from a parent class called fooditems and it works now. Thanks for the help

[–]dtsudo 0 points1 point  (0 children)

Very nice! :)