Can you write a C# method to total all the even numbers in an array of ints?
Submitted by: MuhammadThis is an open-ended coding question that is likely to produce a variety of answers. What you're really looking for is how the developer chooses to solve the problem. Do they settle for the obvious one-liner, return intArray.Where(i => i % 2 == 0).sum() or will they notice the high probability of overflow and instead opt for something more nuanced like the sample answer below?
static long TotalAllEvenInts(int[] intArray) {
return (from i in intArray where i % 2 == 0 select (long)i).Sum();
}
Experienced C# developers will take this as an opportunity to show off their knowledge of C# language constructs that make simple solutions like the one above possible.
Submitted by: Muhammad
static long TotalAllEvenInts(int[] intArray) {
return (from i in intArray where i % 2 == 0 select (long)i).Sum();
}
Experienced C# developers will take this as an opportunity to show off their knowledge of C# language constructs that make simple solutions like the one above possible.
Submitted by: Muhammad
Read Online Unity Developer Job Interview Questions And Answers
Top Unity Developer Questions
☺ | Tell us what Pricing Model Do You Use? |
☺ | Please tell us what are your lifelong dreams? |
☺ | Tell me the basic construction of a C# program. Write a simple program that outputs “Hello World” to the console? |
☺ | Explain me how does C# handle encapsulation? |
☺ | Tell me how articulate are you in expressing your ideas? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |