public static int process exists (string I)
{
Process [] ps=Process. GetProcesses ();
Foreach (Process p in ps)
{
String info="";
Info=p.P rocessName;
If (I==info)
{
return 1;
}
The else
{
return 0;
}
}
}
Shows that not all of the code path has a return value, beg god for help, thank you very much
CodePudding user response:
If there is a public static int process (string I)
{
Process [] ps=Process. GetProcesses ();
Foreach (Process p in ps)
{
String info="";
Info=p.P rocessName;
If (I==info)
{
return 1;
}
The else
{
return 0;
}
}
Return 0
}
CodePudding user response:
Methods may appear may not return a value, 1/f, positive solutionsCodePudding user response:
Could not perform foreach operation, there would be no return value, advice and methods to define a temporary variable in the body, if the assignment, and then return to come out,CodePudding user response:
To this, otherwise the first is not matching, it returns 0public static int process exists (string I)
{
Process [] ps=Process. GetProcesses ();
int result=0;
Foreach (Process p in ps)
{
String info="";
Info=p.P rocessName;
If (I==info)
{
Result=1;
break;
}
}
return result;
}
CodePudding user response:
Or like this:public static int process exists (string I)
{
Process [] ps=Process. GetProcesses ();
If (ps. Any (p=& gt; P.P rocessName==I))
{
return 1;
}
The else
{
return 0;
}
}
CodePudding user response:
1 # positive solutionCodePudding user response:
The rule is simple,Because you can direct the Foreach,
The compiler cannot determine the ps have value,
So, on the outside of the foreach need a return, to represent if not into the traversal, so too does return a value
CodePudding user response:
Public static bool ProcessIsExisted (string processName)
{
Process [] ps=Process. GetProcesses ();
Foreach (Process p in ps)
{
If (p.P rocessName==processName)
{
return true;
}
}
return false;
}
Rewrite and compare yourself,
CodePudding user response:
Do you want to ensure that any case the return value, ps. Not a Length=0CodePudding user response:
You finally add a return is not good, you should consider to whether have returned may be goodCodePudding user response:
# 4, # 5, # 8 is the truth, no problem with the other compilation, logic has a problem,CodePudding user response: