Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 6.0 Programming with Visual Studio 2015
This is the forum to discuss the Wrox book Beginning C# 6.0 Programming with Visual Studio 2015 by Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid; ISBN: 978-1-119-09668-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 6.0 Programming with Visual Studio 2015 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 11th, 2019, 01:14 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2017
Posts: 3
Thanks: 0
Thanked 2 Times in 1 Post
Default Chapter 26 Intro to LINQ

This issue is actually from beginning-microsoft-visual-c-2008-isbn-978-0-470-19135-4-400. I have that book and unfortunately the thread is closed there so I want to post my issue here so any others can benefit from a solution. Since this chapter is just the introduction to LINQ I don't think there will be too many differences from the code then (2008) as compared to now (2019).

On page 865, I typed the code exactly to create the generateLotsOfNumbers() function but receive this error when trying to compile:

Code:
'Program.generateLotsOfNumbers(int)': not all code paths return a value
I'm not at all sure what's going on as the book indicates there is nothing wrong with this code.

code:
Code:
private static int[] generateLotsOfNumbers(int count)
        {
            Random generator = new Random(0);
            int[] result = new int[count];
            
            for (int i = 0; i < count; i++)
            {
                result[i] = generator.Next();
            }
        }
  #2 (permalink)  
Old March 11th, 2019, 02:31 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2017
Posts: 3
Thanks: 0
Thanked 2 Times in 1 Post
Default I forgot to add return result;

Well I found out what I did wrong. It turns out that I forgot to return the result. So not wonder the program would not compile.

Here's the code I needed to add:

Code:
return result;
So the whole function needs to look like this:
Code:
private static int[] generateLotsOfNumbers(int count)
        {
            Random generator = new Random(0);
            int[] result = new int[count];
            
            for (int i = 0; i < count; i++)
            {
                result[i] = generator.Next();
            }
            
             return result;

        }


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 26 Event Projections skupena BOOK: Patterns, Principles and Practices of Domain-Driven Design 1 September 3rd, 2015 02:03 PM
Chapter 2, page 26 - Try it Out marsch BOOK: Beginning iOS 5 Application Development 2 November 6th, 2012 01:43 AM
CHAPTER 2 page 26 -27 joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 August 3rd, 2009 07:03 PM
chapter 26 code alfmeiggs BOOK: Excel 2003 VBA Programmer's Reference 0 November 3rd, 2005 05:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.