Привет!
Я новичок в C# и недавно начал изучать функции. Мне надо сделать программу которая запрашивает числа, знак и выполняет действие (калькулятор короче). Но я столкнулся с проблемой, вот как она звучит:
Серьезность Код Описание Проект Файл Строка Состояние подавления
Ошибка CS0161 ‘»Program.Nikita(int, int, char)»: не все пути к коду возвращают значение.
вот код программы:
public static int Nikita(int a, int b, char d)
{
switch (d)
{
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
return a / b;
default:
Console.WriteLine("Ошибка");
break;
}
//return a - b;
}
static void Main(string[] args)
{
{
Console.Write("вевдите первое число: ");
int am = (int)Convert.ToInt64(Console.ReadLine());
Console.Write("введите знак: ");
char dm = Convert.ToChar(Console.ReadLine());
Console.Write("введите второе число: ");
int bm = (int)Convert.ToInt64(Console.ReadLine());
int resault = Nikita(am, bm, dm);
Console.WriteLine(am);
Console.WriteLine(bm);
Console.WriteLine(dm);
Console.WriteLine(resault);
}
}
}
}
I’m trying to write code that returns whether or not a given integer is divisible evenly by 1 to 20,
but I keep receiving the following error:
error CS0161: ‘ProblemFive.isTwenty(int)’: not all code paths return a value
Here is my code:
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;
}
}
}
user2864740
58.8k14 gold badges137 silver badges211 bronze badges
asked Jan 17, 2014 at 20:47
2
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
}
answered Jan 17, 2014 at 20:53
4
The compiler doesn’t get the intricate logic where you return in the last iteration of the loop, so it thinks that you could exit out of the loop and end up not returning anything at all.
Instead of returning in the last iteration, just return true after the loop:
public static bool isTwenty(int num) {
for(int j = 1; j <= 20; j++) {
if(num % j != 0) {
return false;
}
}
return true;
}
Side note, there is a logical error in the original code. You are checking if num == 20 in the last condition, but you should have checked if j == 20. Also checking if num % j == 0 was superflous, as that is always true when you get there.
answered Jan 17, 2014 at 21:48
GuffaGuffa
679k108 gold badges728 silver badges999 bronze badges
0
I also experienced this problem and found the easy solution to be
public string ReturnValues()
{
string _var = ""; // Setting an innitial value
if (.....) // Looking at conditions
{
_var = "true"; // Re-assign the value of _var
}
return _var; // Return the value of var
}
This also works with other return types and gives the least amount of problems
The initial value I chose was a fall-back value and I was able to re-assign the value as many times as required.
Alan Moore
6,4956 gold badges52 silver badges67 bronze badges
answered Jul 27, 2014 at 14:25
EvertEvert
891 silver badge2 bronze badges
I like to beat dead horses, but I just wanted to make an additional point:
First of all, the problem is that not all conditions of your control structure have been addressed. Essentially, you’re saying if a, then this, else if b, then this. End. But what if neither? There’s no way to exit (i.e. not every ‘path’ returns a value).
My additional point is that this is an example of why you should aim for a single exit if possible. In this example you would do something like this:
bool result = false;
if(conditionA)
{
DoThings();
result = true;
}
else if(conditionB)
{
result = false;
}
else if(conditionC)
{
DoThings();
result = true;
}
return result;
So here, you will always have a return statement and the method always exits in one place. A couple things to consider though… you need to make sure that your exit value is valid on every path or at least acceptable. For example, this decision structure only accounts for three possibilities but the single exit can also act as your final else statement. Or does it? You need to make sure that the final return value is valid on all paths. This is a much better way to approach it versus having 50 million exit points.
answered Jan 27, 2014 at 6:29
SinaestheticSinaesthetic
11.1k26 gold badges103 silver badges174 bronze badges
Or simply do this stuff:
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;
}
else
{
return false;
}
}
}
ForceVII
3672 silver badges15 bronze badges
answered Feb 5, 2014 at 12:25
DareDevilDareDevil
5,2196 gold badges50 silver badges86 bronze badges
1
This usually happens to me if I misplace a return statement, for example:

Adding a return statement, or in my case, moving it to correct scope will do the trick:

answered Dec 6, 2019 at 15:57
![]()
Mirza SisicMirza Sisic
2,3574 gold badges26 silver badges36 bronze badges
1
Have a look at this one. It is the Ternary operator in C#.
bool BooleanValue = (num % 3 != 0) ? true : false;
This is just to show the principle; you can return True or False (or even integer or string) depending on the outcome of something on the left side of the question mark. Nice operator, this.
Three alternatives together:
public bool test1()
{
int num = 21;
bool BooleanValue = (num % 3 != 0) ? true : false;
return BooleanValue;
}
public bool test2()
{
int num = 20;
bool test = (num % 3 != 0);
return test;
}
Even Shorter:
public bool test3()
{
int num = 20;
return (bool)(num % 3 != 0);
}
answered Jan 18, 2014 at 22:50
![]()
netfednetfed
5867 silver badges18 bronze badges
class Program
{
double[] a = new double[] { 1, 3, 4, 8, 21, 38 };
double[] b = new double[] { 1, 7, 19, 3, 2, 24 };
double[] result;
public double[] CheckSorting()
{
for(int i = 1; i < a.Length; i++)
{
if (a[i] < a[i - 1])
result = b;
else
result = a;
}
return result;
}
static void Main(string[] args)
{
Program checkSorting = new Program();
checkSorting.CheckSorting();
Console.ReadLine();
}
}
This should work, otherwise i got the error that not all codepaths return a value. Therefor i set the result as the returned value, which is set as either B or A depending on which is true
answered Jun 1, 2017 at 13:16
Not all code path
s return a value.
sol:-
To solve the error, make sure to return a value from all code paths in the function or set noImplicitReturns to false in your tsconfig.json file.
answered yesterday
New contributor
Jeeva M is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I’m trying to write code that returns whether or not a given integer is divisible evenly by 1 to 20,
but I keep receiving the following error:
error CS0161: ‘ProblemFive.isTwenty(int)’: not all code paths return a value
Here is my code:
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;
}
}
}
user2864740
58.8k14 gold badges137 silver badges211 bronze badges
asked Jan 17, 2014 at 20:47
2
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
}
answered Jan 17, 2014 at 20:53
4
The compiler doesn’t get the intricate logic where you return in the last iteration of the loop, so it thinks that you could exit out of the loop and end up not returning anything at all.
Instead of returning in the last iteration, just return true after the loop:
public static bool isTwenty(int num) {
for(int j = 1; j <= 20; j++) {
if(num % j != 0) {
return false;
}
}
return true;
}
Side note, there is a logical error in the original code. You are checking if num == 20 in the last condition, but you should have checked if j == 20. Also checking if num % j == 0 was superflous, as that is always true when you get there.
answered Jan 17, 2014 at 21:48
GuffaGuffa
679k108 gold badges728 silver badges999 bronze badges
0
I also experienced this problem and found the easy solution to be
public string ReturnValues()
{
string _var = ""; // Setting an innitial value
if (.....) // Looking at conditions
{
_var = "true"; // Re-assign the value of _var
}
return _var; // Return the value of var
}
This also works with other return types and gives the least amount of problems
The initial value I chose was a fall-back value and I was able to re-assign the value as many times as required.
Alan Moore
6,4956 gold badges52 silver badges67 bronze badges
answered Jul 27, 2014 at 14:25
EvertEvert
891 silver badge2 bronze badges
I like to beat dead horses, but I just wanted to make an additional point:
First of all, the problem is that not all conditions of your control structure have been addressed. Essentially, you’re saying if a, then this, else if b, then this. End. But what if neither? There’s no way to exit (i.e. not every ‘path’ returns a value).
My additional point is that this is an example of why you should aim for a single exit if possible. In this example you would do something like this:
bool result = false;
if(conditionA)
{
DoThings();
result = true;
}
else if(conditionB)
{
result = false;
}
else if(conditionC)
{
DoThings();
result = true;
}
return result;
So here, you will always have a return statement and the method always exits in one place. A couple things to consider though… you need to make sure that your exit value is valid on every path or at least acceptable. For example, this decision structure only accounts for three possibilities but the single exit can also act as your final else statement. Or does it? You need to make sure that the final return value is valid on all paths. This is a much better way to approach it versus having 50 million exit points.
answered Jan 27, 2014 at 6:29
SinaestheticSinaesthetic
11.1k26 gold badges103 silver badges174 bronze badges
Or simply do this stuff:
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;
}
else
{
return false;
}
}
}
ForceVII
3672 silver badges15 bronze badges
answered Feb 5, 2014 at 12:25
DareDevilDareDevil
5,2196 gold badges50 silver badges86 bronze badges
1
This usually happens to me if I misplace a return statement, for example:

Adding a return statement, or in my case, moving it to correct scope will do the trick:

answered Dec 6, 2019 at 15:57
![]()
Mirza SisicMirza Sisic
2,3574 gold badges26 silver badges36 bronze badges
1
Have a look at this one. It is the Ternary operator in C#.
bool BooleanValue = (num % 3 != 0) ? true : false;
This is just to show the principle; you can return True or False (or even integer or string) depending on the outcome of something on the left side of the question mark. Nice operator, this.
Three alternatives together:
public bool test1()
{
int num = 21;
bool BooleanValue = (num % 3 != 0) ? true : false;
return BooleanValue;
}
public bool test2()
{
int num = 20;
bool test = (num % 3 != 0);
return test;
}
Even Shorter:
public bool test3()
{
int num = 20;
return (bool)(num % 3 != 0);
}
answered Jan 18, 2014 at 22:50
![]()
netfednetfed
5867 silver badges18 bronze badges
class Program
{
double[] a = new double[] { 1, 3, 4, 8, 21, 38 };
double[] b = new double[] { 1, 7, 19, 3, 2, 24 };
double[] result;
public double[] CheckSorting()
{
for(int i = 1; i < a.Length; i++)
{
if (a[i] < a[i - 1])
result = b;
else
result = a;
}
return result;
}
static void Main(string[] args)
{
Program checkSorting = new Program();
checkSorting.CheckSorting();
Console.ReadLine();
}
}
This should work, otherwise i got the error that not all codepaths return a value. Therefor i set the result as the returned value, which is set as either B or A depending on which is true
answered Jun 1, 2017 at 13:16
Not all code path
s return a value.
sol:-
To solve the error, make sure to return a value from all code paths in the function or set noImplicitReturns to false in your tsconfig.json file.
answered yesterday
New contributor
Jeeva M is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
- Remove From My Forums
-
Question
-
I am getting the following error I understand I am missing something but I have no idea what as I am still learning. Any help would be great
error message:
—— Build started: Project: e:projectsChromeWebService, Configuration: Debug .NET ——
Validating Web Site
Building directory ‘/ChromeWebService/App_WebReferences/’.
Building directory ‘/ChromeWebService/App_Code/’.e:projectsChromeWebServiceApp_CodeChromeWebService.cs(27,19): error CS0161: ‘ChromeWebService.getVin()’: not all code paths return a value
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========Here is the code:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using com.chrome.platform.AutomotiveDescriptionService5;/// <summary>
/// Summary description for ChromeWebService
/// </summary>
[WebService(Namespace = «http://arknet.arkona.com/ChromeWebService»)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ChromeWebService : System.Web.Services.WebService {public ChromeWebService () {
//Uncomment the following line if using designed components
//InitializeComponent();}
[WebMethod]
public string getVin()
{AutomotiveDescriptionService5 ads = new AutomotiveDescriptionService5();
AccountInfo accountInfo = new AccountInfo();
accountInfo.accountNumber = «xxxxxxxx»;
accountInfo.accountSecret = «xxxxxxxxxxxx»;
accountInfo.locale = new Locale();
accountInfo.locale.language = «en»;
accountInfo.locale.country = «US»;
String Vin = «»;
String manufactureModelCode = «»;
String trimName = «»;
String manufactoureOptionCodes = «»;
String equipmentDescriptions = «»;
String wheelBase = «»;
String exteriorColorName = «»;
String useSafeStandards = «»;
String excludeFleetOnlyStyles = «»;
String includeAvailableEquipment = «»;
String version = «»;
DataVersionsRequest dataVersionRequest = new DataVersionsRequest();
dataVersionRequest.accountInfo = accountInfo;
DataVersion[] dataVersions = ads.getDataVersions(dataVersionRequest);
for (int i = 0; i < dataVersions.Length; i++)
{
if (dataVersions
.country == «US»)
{
version = dataVersions
.country + » » + dataVersions
.build + » (» +
dataVersions
.date + «)»;
}
}VehicleInformation vehicleInfo = null;
if (Vin != null && Vin.Length > 0)
{
VehicleInformationFromVinRequest vinRequest = new
VehicleInformationFromVinRequest();
vinRequest.accountInfo = accountInfo;vinRequest.vin = Vin;
vinRequest.manufacturerModelCode = manufactureModelCode;
vinRequest.trimName = trimName;
if (manufactoureOptionCodes.Length > 0)
{
vinRequest.manufacturerOptionCodes = manufactoureOptionCodes.Split(new char[] { ‘,’ });
}
if (equipmentDescriptions.Length > 0)
{
vinRequest.equipmentDescriptions = equipmentDescriptions.Split(new char[] { ‘,’ });
}
if (wheelBase.Length > 0)
{
vinRequest.wheelBase = Double.Parse(wheelBase);
}
vinRequest.exteriorColorName = exteriorColorName;
vinRequest.useSafeStandards = useSafeStandards != null;
vinRequest.excludeFleetOnlyStyles = excludeFleetOnlyStyles != null;
vinRequest.includeAvailableEquipment = includeAvailableEquipment != null;vinRequest.enableEnrichedVehicleEquipment = false;
vehicleInfo = ads.getVehicleInformationFromVin(vinRequest);
}
Thank you for taking the time to look at this.
Answers
-
got the answer I needed public void getVin() instead of public string getVin() whelp still learning
-
The message is telling you that the problem lies in a method called ‘ChromeWebService.getVin’. The problem is that there are some code paths (i.e., some routes through the code in getVin) that cause getVin to exit without returning a value.
Since getVin is declared to be of type string, all paths through the method should end up calling return.
For example, in the code below, the execution path through the method «foo» returns the value «a string» if expression evaluates to true. But, if expression evaluates to false then the code path just drops down to the end of «foo» and exits the method without calling return which would cause a CS0161 error.
Uncommenting either of the commented return statements would fix the error.
Code Snippet
string foo()
{
bool expression = true;
if (expression)
{
return «a string»;
}
else
{
// should return something here…
//return «another string»;
}
// … or return something here
//return «yet another string»;
}
All the compiler error messages
areshould be documented in the MSDN library. Go to msdn.microsoft.com and enter CS0161 in the search box and you should get an explaination of the error and some sample code demonstrating how the error can be caused.
- Remove From My Forums
-
Question
-
I am getting the following error I understand I am missing something but I have no idea what as I am still learning. Any help would be great
error message:
—— Build started: Project: e:projectsChromeWebService, Configuration: Debug .NET ——
Validating Web Site
Building directory ‘/ChromeWebService/App_WebReferences/’.
Building directory ‘/ChromeWebService/App_Code/’.e:projectsChromeWebServiceApp_CodeChromeWebService.cs(27,19): error CS0161: ‘ChromeWebService.getVin()’: not all code paths return a value
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========Here is the code:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using com.chrome.platform.AutomotiveDescriptionService5;/// <summary>
/// Summary description for ChromeWebService
/// </summary>
[WebService(Namespace = «http://arknet.arkona.com/ChromeWebService»)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ChromeWebService : System.Web.Services.WebService {public ChromeWebService () {
//Uncomment the following line if using designed components
//InitializeComponent();}
[WebMethod]
public string getVin()
{AutomotiveDescriptionService5 ads = new AutomotiveDescriptionService5();
AccountInfo accountInfo = new AccountInfo();
accountInfo.accountNumber = «xxxxxxxx»;
accountInfo.accountSecret = «xxxxxxxxxxxx»;
accountInfo.locale = new Locale();
accountInfo.locale.language = «en»;
accountInfo.locale.country = «US»;
String Vin = «»;
String manufactureModelCode = «»;
String trimName = «»;
String manufactoureOptionCodes = «»;
String equipmentDescriptions = «»;
String wheelBase = «»;
String exteriorColorName = «»;
String useSafeStandards = «»;
String excludeFleetOnlyStyles = «»;
String includeAvailableEquipment = «»;
String version = «»;
DataVersionsRequest dataVersionRequest = new DataVersionsRequest();
dataVersionRequest.accountInfo = accountInfo;
DataVersion[] dataVersions = ads.getDataVersions(dataVersionRequest);
for (int i = 0; i < dataVersions.Length; i++)
{
if (dataVersions
.country == «US»)
{
version = dataVersions
.country + » » + dataVersions
.build + » (» +
dataVersions
.date + «)»;
}
}VehicleInformation vehicleInfo = null;
if (Vin != null && Vin.Length > 0)
{
VehicleInformationFromVinRequest vinRequest = new
VehicleInformationFromVinRequest();
vinRequest.accountInfo = accountInfo;vinRequest.vin = Vin;
vinRequest.manufacturerModelCode = manufactureModelCode;
vinRequest.trimName = trimName;
if (manufactoureOptionCodes.Length > 0)
{
vinRequest.manufacturerOptionCodes = manufactoureOptionCodes.Split(new char[] { ‘,’ });
}
if (equipmentDescriptions.Length > 0)
{
vinRequest.equipmentDescriptions = equipmentDescriptions.Split(new char[] { ‘,’ });
}
if (wheelBase.Length > 0)
{
vinRequest.wheelBase = Double.Parse(wheelBase);
}
vinRequest.exteriorColorName = exteriorColorName;
vinRequest.useSafeStandards = useSafeStandards != null;
vinRequest.excludeFleetOnlyStyles = excludeFleetOnlyStyles != null;
vinRequest.includeAvailableEquipment = includeAvailableEquipment != null;vinRequest.enableEnrichedVehicleEquipment = false;
vehicleInfo = ads.getVehicleInformationFromVin(vinRequest);
}
Thank you for taking the time to look at this.
Answers
-
got the answer I needed public void getVin() instead of public string getVin() whelp still learning
-
The message is telling you that the problem lies in a method called ‘ChromeWebService.getVin’. The problem is that there are some code paths (i.e., some routes through the code in getVin) that cause getVin to exit without returning a value.
Since getVin is declared to be of type string, all paths through the method should end up calling return.
For example, in the code below, the execution path through the method «foo» returns the value «a string» if expression evaluates to true. But, if expression evaluates to false then the code path just drops down to the end of «foo» and exits the method without calling return which would cause a CS0161 error.
Uncommenting either of the commented return statements would fix the error.
Code Snippet
string foo()
{
bool expression = true;
if (expression)
{
return «a string»;
}
else
{
// should return something here…
//return «another string»;
}
// … or return something here
//return «yet another string»;
}
All the compiler error messages
areshould be documented in the MSDN library. Go to msdn.microsoft.com and enter CS0161 in the search box and you should get an explaination of the error and some sample code demonstrating how the error can be caused.
- Remove From My Forums
-
Question
-
I am getting the following error I understand I am missing something but I have no idea what as I am still learning. Any help would be great
error message:
—— Build started: Project: e:projectsChromeWebService, Configuration: Debug .NET ——
Validating Web Site
Building directory ‘/ChromeWebService/App_WebReferences/’.
Building directory ‘/ChromeWebService/App_Code/’.e:projectsChromeWebServiceApp_CodeChromeWebService.cs(27,19): error CS0161: ‘ChromeWebService.getVin()’: not all code paths return a value
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========Here is the code:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using com.chrome.platform.AutomotiveDescriptionService5;/// <summary>
/// Summary description for ChromeWebService
/// </summary>
[WebService(Namespace = «http://arknet.arkona.com/ChromeWebService»)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ChromeWebService : System.Web.Services.WebService {public ChromeWebService () {
//Uncomment the following line if using designed components
//InitializeComponent();}
[WebMethod]
public string getVin()
{AutomotiveDescriptionService5 ads = new AutomotiveDescriptionService5();
AccountInfo accountInfo = new AccountInfo();
accountInfo.accountNumber = «xxxxxxxx»;
accountInfo.accountSecret = «xxxxxxxxxxxx»;
accountInfo.locale = new Locale();
accountInfo.locale.language = «en»;
accountInfo.locale.country = «US»;
String Vin = «»;
String manufactureModelCode = «»;
String trimName = «»;
String manufactoureOptionCodes = «»;
String equipmentDescriptions = «»;
String wheelBase = «»;
String exteriorColorName = «»;
String useSafeStandards = «»;
String excludeFleetOnlyStyles = «»;
String includeAvailableEquipment = «»;
String version = «»;
DataVersionsRequest dataVersionRequest = new DataVersionsRequest();
dataVersionRequest.accountInfo = accountInfo;
DataVersion[] dataVersions = ads.getDataVersions(dataVersionRequest);
for (int i = 0; i < dataVersions.Length; i++)
{
if (dataVersions
.country == «US»)
{
version = dataVersions
.country + » » + dataVersions
.build + » (» +
dataVersions
.date + «)»;
}
}VehicleInformation vehicleInfo = null;
if (Vin != null && Vin.Length > 0)
{
VehicleInformationFromVinRequest vinRequest = new
VehicleInformationFromVinRequest();
vinRequest.accountInfo = accountInfo;vinRequest.vin = Vin;
vinRequest.manufacturerModelCode = manufactureModelCode;
vinRequest.trimName = trimName;
if (manufactoureOptionCodes.Length > 0)
{
vinRequest.manufacturerOptionCodes = manufactoureOptionCodes.Split(new char[] { ‘,’ });
}
if (equipmentDescriptions.Length > 0)
{
vinRequest.equipmentDescriptions = equipmentDescriptions.Split(new char[] { ‘,’ });
}
if (wheelBase.Length > 0)
{
vinRequest.wheelBase = Double.Parse(wheelBase);
}
vinRequest.exteriorColorName = exteriorColorName;
vinRequest.useSafeStandards = useSafeStandards != null;
vinRequest.excludeFleetOnlyStyles = excludeFleetOnlyStyles != null;
vinRequest.includeAvailableEquipment = includeAvailableEquipment != null;vinRequest.enableEnrichedVehicleEquipment = false;
vehicleInfo = ads.getVehicleInformationFromVin(vinRequest);
}
Thank you for taking the time to look at this.
Answers
-
got the answer I needed public void getVin() instead of public string getVin() whelp still learning
-
The message is telling you that the problem lies in a method called ‘ChromeWebService.getVin’. The problem is that there are some code paths (i.e., some routes through the code in getVin) that cause getVin to exit without returning a value.
Since getVin is declared to be of type string, all paths through the method should end up calling return.
For example, in the code below, the execution path through the method «foo» returns the value «a string» if expression evaluates to true. But, if expression evaluates to false then the code path just drops down to the end of «foo» and exits the method without calling return which would cause a CS0161 error.
Uncommenting either of the commented return statements would fix the error.
Code Snippet
string foo()
{
bool expression = true;
if (expression)
{
return «a string»;
}
else
{
// should return something here…
//return «another string»;
}
// … or return something here
//return «yet another string»;
}
All the compiler error messages
areshould be documented in the MSDN library. Go to msdn.microsoft.com and enter CS0161 in the search box and you should get an explaination of the error and some sample code demonstrating how the error can be caused.