Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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 1 Time 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();
            }
        }
Reply With Quote
  #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 1 Time 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;

        }
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.