Error cs1503 argument 1 cannot convert from void to string

Собственно у DXMenuItem есть конструктор с параметрами string, void.Так вот ему не нравится как я вызываю функцию Count с параметрами.Не может конвертировать тип.Как мне правильно вызвать функцию с

введите сюда описание изображенияСкрин проги

Собственно у DXMenuItem есть конструктор с параметрами string, void.Так вот ему не нравится как я вызываю функцию Count с параметрами.Не может конвертировать тип.Как мне правильно вызвать функцию с параметрами?Подозреваю что надо использовать лямбда-функцию,но не уверен.

задан 25 окт 2018 в 16:38

Kama's user avatar

KamaKama

414 бронзовых знака

3

У конструктора DxMenuItem, всего две перегрузки с двумя параметрами:

DXMenuItem(string caption, DXMenuItemPriority priority)
DXMenuItem(string caption, EventHandler click)

Вероятнее всего имелась ввиду вторая перегрузка принимающая обработчик click.

В этом случае действительно можно передать lambda

new DxMenuItem(str, (s,e)=> Count(...))

ответ дан 25 окт 2018 в 17:09

Grundy's user avatar

GrundyGrundy

79k9 золотых знаков73 серебряных знака131 бронзовый знак

1

Дело в ожидаемых типах параметров конструктора DXMenuItem. Вряд ли тип второго параметра void (.

Собственно у делегата DXMenuItem есть конструктор с параметрами
string, void.

Маловероятно также, что тип DXMenuItem является делегатом. Похоже, в процитированной фразе Вы пытаетесь описать сигнатуру метода: параметр — string, возвращаемое значение — void.

ответ дан 25 окт 2018 в 17:00

2

  • Remove From My Forums
  • Question

  • Hi, Please I am new to MVC. I am working on a project.
    Each time I try to build it, it throw «Error CS1503, cannot convert from string…
    Here is my code in question:

    namespace MySaleMVC
    {
        public static class GlobalVariables
        {
            public static HttpClient WebApiClient = new HttpClient();

            static GlobalVariables()
            {
                WebApiClient.BaseAddress = new FormUrlEncodedContent(«http://localhost:52859/api/»);
                WebApiClient.DefaultRequestHeaders.Clear();
                WebApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(«application/json»));
            }
        }
    }

    Please help me correct the error and let me move on.

    Thanks in Advance

    John MC

Answers

    • Proposed as answer by

      Wednesday, October 30, 2019 6:50 PM

    • Marked as answer by
      Bruce Eitman
      Monday, November 11, 2019 12:26 PM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.IO;
using System.Collections.Generic;
 
namespace Grapher
{ class Program
{
    static void Main(string[] args)
    {
        string[] data = File.ReadAllLines("массив.txt");
        int length = data[0].Split(';').Length, i;
        Graph graph = new Graph();
        for (i = 0; i < length; i++)
        {
            string[] str = data[i].Split(';');
            var vertices = new Dictionary<char, int>();
            for (int j = 0; j < length; j++)
                if (Convert.ToInt32(str[j]) != 0)
                    vertices.Add(Char.Parse((j + 1).ToString()), Convert.ToInt32(str[j]));
 
            graph.add_vertex(Char.Parse((i + 1).ToString()), vertices);
        }
       
        string start = Console.ReadLine(); // Номер начального пункта
            string end = Console.ReadLine(); // Номер конечного пункта
        var result = graph.all_ways(start, end, "", 0);
 
        using (var sw = new StreamWriter("результат.txt"))
        {
            foreach (var item in result)
                sw.WriteLine(item);
            sw.WriteLine("Кратчайшее расстояние равно " + graph.shortest_path(start, end));
        }
        Console.Write("Результат был сохранен в файле результат.txt");
        Console.ReadLine();
    }
}
}
 
 
    class Graph
    {
        Dictionary<char, Dictionary<char, int>> vertices = new Dictionary<char, Dictionary<char, int>>();
        public void add_vertex(char name, Dictionary<char, int> edges)
        {
            vertices[name] = edges;
        }
        public List<string> all_ways(char current, char end, string path, int weight)
        {
            List<string> pathes = new List<string>();
            if (path.IndexOf(current.ToString() + " ") != -1)
 
                return pathes;
            else
                if (path == "")
                path = current.ToString() + " = 0";
            else
            {
                int index = path.IndexOf("=");
                string temp = path.Substring(0, index);
                string sum = path.Substring(index + 1);
                weight += Convert.ToInt32(sum);
                path = temp + "-> " + current.ToString() + " = " + weight.ToString();
            }
            if (current == end)
            {
                pathes.Add(path);
                return pathes;
            }
            foreach (KeyValuePair<char, int> pair in vertices[current])
            {
                List<string> result = all_ways(pair.Key, end, path, pair.Value);
                if (result.Count != 0)
                    pathes.AddRange(result);
            }
            return pathes;
        }
        public int shortest_path(char start, char finish)
        {
            var previous = new Dictionary<char, char>();
            var distances = new Dictionary<char, int>();
            var nodes = new List<char>();
 
            List<char> path = null;
 
            foreach (var vertex in vertices)
            {
                if (vertex.Key == start)
                {
                    distances[vertex.Key] = 0;
                }
                else
                {
                    distances[vertex.Key] = int.MaxValue;
                }
 
                nodes.Add(vertex.Key);
            }
 
            while (nodes.Count != 0)
            {
                nodes.Sort((x, y) => distances[x] - distances[y]);
 
                var smallest = nodes[0];
                nodes.Remove(smallest);
 
                if (smallest == finish)
                {
                    path = new List<char>();
                    while (previous.ContainsKey(smallest))
                    {
                        path.Add(smallest);
                        smallest = previous[smallest];
                    }
 
                    break;
                }
 
                if (distances[smallest] == int.MaxValue)
                {
                    break;
                }
 
                foreach (var neighbor in vertices[smallest])
                {
                    var alt = distances[smallest] + neighbor.Value;
                    if (alt < distances[neighbor.Key])
                    {
                        distances[neighbor.Key] = alt;
                        previous[neighbor.Key] = smallest;
                    }
                }
            }
            if (path.Count > 0)
                return distances[path[0]];
            else
                return 0;
        }
    }

Понравилась статья? Поделить с друзьями:
  • Error cs1503 argument 1 cannot convert from unityengine vector3 to float
  • Error cs1503 argument 1 cannot convert from system collections ienumerable to string
  • Error cs1503 argument 1 cannot convert from string to int
  • Error cs1503 argument 1 cannot convert from string to char
  • Error cs0034 operator is ambiguous on operands of type vector3 and vector2