Click here to Skip to main content
12,349,582 members (27,567 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

2.3K views
Posted

Logical and arithmetic operations in C#

, 29 Jun 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Instead of doing it yourself, a better way would be to use LINQ for that purpose. Here is an example for addition:int[] numbers = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };int result = numbers.Aggregate((x, y) => x + y).ToString());and for multiplication:long[] numbers = { 4, 5, 6, 7,...

Instead of doing it yourself, a better way would be to use LINQ for that purpose. Here is an example for addition:

int[] numbers = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
int result = numbers.Aggregate((x, y) => x + y).ToString());

and for multiplication:

long[] numbers = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
long result = numbers.Aggregate(1L, (x, y) => x * y).ToString());

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Philippe Mori
Software Developer (Senior)
Canada Canada
Programmer at Maid LABS from 2003 (www.maidlabs.com)

Programmer-Analyst at Viasat Geo Technoligies from 1995 to 2002 (www.viasat-geo.com).

I have studied at École Polytechnique de Montréal in computer engineering.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 29 Jun 2011
Article Copyright 2011 by Philippe Mori
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid