logo CodeStepByStep logo


Write a method named SumOf2020 that accepts a string representing a file name as a parameter, reads the given file, finds the two numbers in that file that sum to exactly 2020, and returns the product of those numbers. The file will contain exactly one non-negative integer per line. For example, if the file named numbers.txt contains the following values:


The two entries that sum to 2020 are 1721 and 299. Multiplying them together produces a product of 1721 * 299 = 514579, so the call of SumOf2020("numbers.txt") should return 514579.

You may assume that the file exists and is readable, that it follows the format described above, and that there will be exactly one pair of values in the file that sum to 2020.

Method: Write a C# method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.