You’re missing a return
statement.
When the compiler looks at your code, it’s sees a third path (the else
you didn’t code for) that could occur but doesn’t return a value. Hence not all code paths return a value
.
For my suggested fix, I put a return
after your loop ends. The other obvious spot – adding an else
that had a return
value to the if-else-if
– would break the for
loop.
public static bool isTwenty(int num) { for(int j = 1; j <= 20; j++) { if(num % j != 0) { return false; } else if(num % j == 0 && num == 20) { return true; } } return false; //This is your missing statement }
Related Posts:
- C# compiler error: “not all code paths return a value”
- C# compiler error: “not all code paths return a value”
- Return multiple values to a method caller
- How do I exit from a function?
- How can I convert String to Int?
- What is a NullReferenceException, and how do I fix it?
- How to find child of a GameObject or the script attached to child GameObject via script
- Process cannot access the file because it is being used by another proess
- How to convert JSON to XML or XML to JSON?
- Virustotal Trapmine suspicious.low.ml.score
- Convert int to string?
- Priority queue in .Net
- What is the difference between int, Int16, Int32 and Int64?
- Adding values to a C# array
- How can I add ” character to a multi line string declaration in C#?
- Input string was not in a correct format
- The request was aborted: Could not create SSL/TLS secure channel
- C# An established connection was aborted by the software in your host machine
- OnCollisionEnter() not working in Unity3D
- Difference between virtual and abstract methods
- How to open .dll files to see what is written inside?
- how does Request.QueryString work?
- C# Java HashMap equivalent
- System.Net.Http: missing from namespace? (using .net 4.5)
- Windows .NET API / Windows 7 / Bluetooth communication with Intel Curie Arduino / Genuino 101
- WFP Grid: MouseRightButtonDown firing occuring BEFORE SelectionChanged on grid. Causing syncing issue
- Can’t add script component because the script class cannot be found?
- ‘do…while’ vs. ‘while’
- Visual Studio /**/ comment shortcut?
- Unable to resolve service for type while attempting to activate
- Nullable object must have a value?
- Sequence contains no elements?
- Multiple Inheritance in C#
- Wait one second in running program
- Deserialize JSON with C#
- “Error while trying to run project: Unable to start program”. Can run program only once. Then VS needs restart
- What is WebResource.axd?
- Associating enums with strings in C#
- Proper Linq where clauses
- Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details
- How to resolve this System.IO.FileNotFoundException
- Visual Studio says “Method must have a return type”
- What is the best way to implement a “timer”?
- How to Use TextureBrush for painting an Image
- How do I read and parse an XML file in C#?
- SmtpException: Unable to read data from the transport connection: net_io_connectionclosed
- How to fix “namespace x already contains a definition for x” error? Happened after converting to VS2010
- How can I get the application’s path in a .NET console application?
- How do I encode and decode a base64 string?
- How to keep console window open
- Tree data structure in C#
- What is 0x10 in decimal?
- Visual Studio: The Operation could not be completed. The parameter is incorrect
- IEnumerable vs List – What to Use? How do they work?
- Member ‘
‘ cannot be accessed with an instance reference - Sequence contains no matching element
- when do you need .ascx files and how would you use them?
- How to convert code from C# to PHP
- How to open a new form from another form
- C# – How to convert string to char?
- The entity type
is not part of the model for the current context - Recommendation for C# Matrix Library
- Deep cloning objects
- Regular expression “^[a-zA-Z]” or “[^a-zA-Z]”
- Excel “External table is not in the expected format.”
- .NET graph library around?
- Input string was not in a correct format
- Verify a method call using Moq
- XmlSerializer – There was an error reflecting type
- Run Command Prompt Commands
- Cannot implicitly convert type ‘System.Collections.Generic.List< >‘ to ‘System.Collections.Generic.IList< >‘
- How can I wait for a thread to finish with .NET?
- The model item passed into the dictionary is of type .. but this dictionary requires a model item of type
- How can I get the active screen dimensions?
- WebException (Status: Protocol Error)
- How to add a new row to datagridview programmatically
- How do I exit a WPF application programmatically?
- OnCollisionEnter is not called in unity
- The name ‘ViewBag’ does not exist in the current context – Visual Studio 2015
- How to create a new object instance from a Type
- Cannot drop database because it is currently in use
- Troubleshooting “program does not contain a static ‘Main’ method” when it clearly does…?
- does not implement interface member
- Differences between SFTP and “FTP over SSH”
- When should I use a List vs a LinkedList
- Remove punctuation from string with Regex
- Unity – How to stop Play Mode in case of infinite loop?
- Go To Definition: “Cannot navigate to the symbol under the caret.”
- Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?
- Is there a keyboard shortcut to maximize the Game window in Unity in Play Mode?
- IF Statement multiple conditions, same statement
- What is the easiest way to handle associative array in c#?
- What does the M stand for in C# Decimal literal notation?
- Iif equivalent in C#
- Convert an array to string
- Quickest way to compare two generic lists for differences
- What is the easiest way to encrypt a password when I save it to the registry?
- LINQ query on a DataTable
- is inaccessible due to its protection level
- Memory Leak caused by System.Drawing.Internal.GPStream