Error cs1525 invalid expression term int

This repository contains .NET Documentation. Contribute to dotnet/docs development by creating an account on GitHub.

Permalink

Cannot retrieve contributors at this time

description title ms.date f1_keywords helpviewer_keywords ms.assetid

Compiler Error CS1525

Compiler Error CS1525

07/20/2015

CS1525

CS1525

7913f589-2f2e-40bc-a27e-0b6930336484

Compiler Error CS1525

Invalid expression term ‘character’

The compiler detected an invalid character in an expression.

The following sample generates CS1525:

// CS1525.cs  
class x  
{  
   public static void Main()  
   {  
      int i = 0;  
      i = i +   // OK - identifier  
      'c' +     // OK - character  
      (5) +     // OK - parenthesis  
      [ +       // CS1525, operator not a valid expression element  
      throw +   // CS1525, keyword not allowed in expression  
      void;     // CS1525, void not allowed in expression  
   }  
}  

An empty label can also generate CS1525, as in the following sample:

// CS1525b.cs  
using System;  
public class MyClass  
{  
   public static void Main()  
   {  
      goto FoundIt;  
      FoundIt:      // CS1525  
      // Uncomment the following line to resolve:  
      // System.Console.Write("Hello");  
   }  
}  

  • Remove From My Forums
  • Question

  • User1554814930 posted

    I
    am following a tutorial and it says type  <%:  but i get this error, when i change to <%=  it works.  A simple thing but I dont have some config or somthing correct somewhere.  Any help is appreciated.

    Description:
    An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1525: Invalid expression term ‘:’

    Source Error:

    Line 8:      <h2><%= Html.Encode(ViewData["Message"]) %></h2>
    Line 9:      <p>
    Line 10: <%: Html.ActionLink("Product List", "Index", "Product") %>
    Line 11:     </p>
    Line 12: </asp:Content>

Answers

    • Marked as answer by

      Thursday, October 7, 2021 12:00 AM

Ошибки при компиляции

Error CS1525 Invalid expression term ‘int’
Error CS1003 Syntax error, ‘,’ expected
Error CS0103 The name ‘generalWeight’ does not exist in the current context
Error CS0103 The name ‘generalWeight’ does not exist in the current context
Error CS0029 Cannot implicitly convert type ‘string’ to ‘int’
Error CS0103 The name ‘changeVisible’ does not exist in the current context

Код:

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DayxtraAlgorithm.View;
using DayxtraAlgorithm.Model;
using DayxtraAlgorithm.Util;


namespace cproject
{
    public partial class traningForm : Form
    {
        Graph graph;
        public traningForm()
        {
            InitializeComponent();
        }

        private void c111_Click(object sender, EventArgs e)
        {

        }

        private void b123_Click(object sender, EventArgs e)
        {

        }

        private void shortgraph_Click(object sender, EventArgs e)
        {
            var first = Int32.Parse(textBox1.Text) - 1;
            var second = Int32.Parse(textBox2.Text) - 1;
            var count = graph.matrix.Count;
            var vertEntities = Creator.createVertexEntities(count);
            var shortestWay = Dayxtra.getShortestWay(graph.matrix, graph.weight, vertEntities, out int generalWeight, first, second);
            label8.Text = "Вес: " + generalWeight.ToString();
            pictureBox2.Image = GraphDisplayer.draw(pictureBox2.Height, pictureBox2.Width, graph, shortestWay);
        }

        private void graph_generation_Click(object sender, EventArgs e)
        {
            int count;
            int posib = textBox4.Text; // отсюда берется число. если написать на форме 20, значит для программы означает 20% т.е. указывается число без знака процента
            if (!Int32.TryParse(textBox3.Text, out count))
            {
                count = 5;
            }
            graph = Creator.createNonDirected(count, posib);
            Creator.createWeight(graph, 5, 20);

            pictureBox2.Image = GraphDisplayer.draw(pictureBox2.Height, pictureBox2.Width, graph);
            changeVisible(true);
        }
    }
}

Dayxtra

Ссылка на DayxtraAlgorithm.Util.

using System;
using System.Collections.Generic;
using System.Linq;
using DayxtraAlgorithm.Model;

namespace DayxtraAlgorithm.Util
{
    public static class Dayxtra
    {
        public static List<int> getShortestWay(List<List<byte?>> matrix, List<List<string>> weight,
            List<VertexEntity> vertexes, out int generalWeight, int first = 0, int second = 0)
        {
            var firstVert = vertexes.FirstOrDefault(x => x.Num == first);
            firstVert.setDist(0);

            if (second == 0)
                second = matrix.Count - 1;

            var finalVert = vertexes.FirstOrDefault(x => x.Num == second);

            while(!finalVert.isSetted)
            {
                var vertex = vertexes.FindAll(x => !x.isSetted).Min();
                int rowNum = vertex.Num;
                for (int i = 0; i < matrix[rowNum].Count; i++)
                {
                    if (matrix[rowNum][i] == 1 && !vertexes[i].isSetted)
                    {
                        setVertex(vertex, vertexes[i], weight[rowNum][i]);
                    }
                    else if (matrix[i][rowNum] == 1 && !vertexes[i].isSetted)
                    {
                        setVertex(vertex, vertexes[i], weight[i][rowNum]);
                    }
                }
                vertex.isSetted = true;

            }

            return getWayBetween(vertexes, out generalWeight, first, second);

        }

        private static void setVertex(VertexEntity vertex, VertexEntity ChildVertex, string weight)
        {
            var newDist = vertex.Dist + Int32.Parse(weight);
            if (ChildVertex.Dist > newDist)
            {
                ChildVertex.setDist(newDist);
                ChildVertex.setPrev(vertex);
            }
        }
        private static List<int> getWayBetween(List<VertexEntity> vertexes, out int genWeight, 
            int first, int second)
        {
            List<int> shortestWay = new List<int>();
            var vertex = vertexes.FirstOrDefault(x => x.Num == second);
            var vertexStart = vertexes.FirstOrDefault(x => x.Num == first);
            genWeight = vertex.Dist;

            while (vertex != null)
            {
                shortestWay.Add(vertex.Num);
                vertex = vertex.Prev;
            }

            return shortestWay;
        }
    }
}

P.S. Помогите исправить ошибки.

Понравилась статья? Поделить с друзьями:
  • Error cs1520 class struct or interface method must have a return type
  • Error cs1519 unexpected symbol in class struct or interface member declaration
  • Error cs1519 invalid token in class struct or interface member declaration unity
  • Error cs1519 invalid token in class record struct or interface member declaration
  • Error cs1519 invalid token float in class struct or interface member declaration