开发者

cannot convert type to bool

开发者 https://www.devze.com 2023-02-08 15:24 出处:网络
public static void PathFinder (Client C, Path Distance) { if (C.Recording) { if(Distance to C.Path[C.PathIndex] < 7);
    public static void PathFinder (Client C, Path Distance)
    {
    if (C.Recording)
    {

      if(Distance to C.Path[C.PathIndex] < 7); 
      {
      if(C.PathIndex + 1< C.Path.Count)
      {
         C.PathIndex++; 
      }
      else
      {
         C.Recording = true;
         C.Path = new List<Coord>();
         C.PathIndex = 0;
         C.Path.Add(new Point(C.X, C.Y));
         C.Path = C.Path.Reverse();
         C.P开发者_开发问答athIndex = 1;
      }
         Coord To = Calculations.PullWeights(MakeCoord(C.X, C.Y), C.Path[C.PathIndex]);
      } 
    }
}

I am getting several errors, but I`m not sure how to fix the problem. I have looked at solutions but am still a little clueless >.<


This line is wrong

if(Distance to C.Path[C.PathIndex] < 7);

Firstly Distance to C.Path[C.PathIndex] is not a valid expression. You need to replace it with an expression that does calculate the distance.

Secondly the semi-colon at the end of the line must not be there. You are literally saying if (x) doNothing();


I would assume the error happens here:

if(Distance to C.Path[C.PathIndex] < 7); 

This doesn't look like a valid C# expression, and that's what gives you the conversion error


  1. if (C.Recording) - if Recording is not a bool Property, then this won't work
  2. if(Distance to C.Path[C.PathIndex] < 7); this isn't legal C#, and loose the trailing semicolon

Update:

I'm not sure if (!C.Recording) will work either. I don't know what the type of Recording is. If it's a bool, then it's all fine, but if not, then you need to create a boolean expression.

For instance, if Recording is a string type, then you'll need to do

if (!string.IsNullOrEmpty(C.Recording)) { ... }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号