Error cs1525 unexpected symbol void

Free source code and tutorials for Software developers and Architects.; Updated: 10 Aug 2020

For a long time I can’t understand what the matter is, it seems like everything is fine everywhere, or maybe I’m blind

Error while compiling: SkyMenu.cs(550,16): error CS1525: Unexpected symbol `void’, expecting `class’, `delegate’, `enum’, `interface’, `partial’, or `struct’

If it doesn’t bother you, please help me

  1  using Oxide.Core.Plugins;
  2  using Oxide.Game.Rust.Cui;
  3  using System;
  4  using System.Collections;
  5  using System.Collections.Generic;
  6  using System.Linq;
  7  using System.Globalization;
  8  using UnityEngine;
  9  using Color = UnityEngine.Color;
 10  using Random = UnityEngine.Random;
 11  
 12  namespace Oxide.Plugins
 13  {
 14      [Info("SkyMenu", "JoyRax", "0.0.1")]
 15      [Description("Menu game info")]
 16      class SkyMenu : RustPlugin
 17      {
 18          #region Vars
 19          [PluginReference] private Plugin ImageLibrary, NTeleportation;
 20          private string MainLayer = "ui_main";
 21  
 22          #endregion 
 23  
 24          #region Configuration
 25  
 26          private class PluginConfig
 27          {
 28              public CuiStandardElementSetting _CuiStandardElementSetting;
 29              public CuiServerNameSetting _CuiServerNameSetting;
 30              public CuiAvatarSetting _CuiAvatarSetting;
 31              public List<CuiUButtonSetting> _CuiUButtonSetting;
 32          }
 33  
 34          private class Anchor
 35          {
 36              public string Min;
 37              public string Max;
 38          }
 39  
 40          private class CuiStandardElementSetting
 41          {
 42              public string BackgroundColor;
 43              public Anchor Anchor;
 44              public bool CursorEnabled;
 45              public string Layer;
 46          }
 47  
 48          private class CuiServerNameSetting
 49          {
 50              public string NameServer;
 51              public string BackgroundColor;
 52              public string TextColor;
 53              public Anchor Anchor;
 54              public string ELParent;
 55              public string ELName;
 56              public string Font;
 57              public int FontSize;
 58          }
 59  
 60          private class CuiAvatarSetting
 61          {
 62              public string BackgroundColor;
 63              public string TextColor;
 64              public Anchor Anchor;
 65              public string ELParent;
 66              public string ELName;
 67              public string ELNameImage;
 68              public string ELNameText;
 69              public string Font;
 70              public int FontSize;
 71          }
 72  
 73          private class CuiStandardButtonSetting 
 74          {
 75              public string BackgroundColor;
 76              public string SmallBackgroundColor;
 77              public string TextColor;
 78              public string ELParent;
 79              public string ELName;
 80              public string ELSmallName;
 81              public string Font;
 82              public int FontSize;
 83              public int FontSizeSmall;
 84          }
 85  
 86          private class CuiUButtonSetting : CuiStandardButtonSetting
 87          {
 88              public Anchor Anchor;
 89              public string SmallText;
 90              public string Text;
 91              public string Command;
 92          }
 93  
 94          private PluginConfig _config;
 95  
 96          protected override void LoadDefaultConfig()
 97          {
 98              Config.WriteObject(GetDefaultConfig(), true);
 99          }
100  
101          private PluginConfig GetDefaultConfig()
102          {
103              return new PluginConfig
104              {
105                  _CuiStandardElementSetting = new CuiStandardElementSetting
106                  {
107                      BackgroundColor = "0 0 0 0.5",
108                      Anchor = new Anchor
109                      {
110                          Min = "0 0",
111                          Max = "1 1"
112                      },
113                      CursorEnabled = true,
114                      Layer = MainLayer
115                  },
116                  _CuiServerNameSetting = new CuiServerNameSetting
117                  {
118                      NameServer = "POISON RUST",
119                      BackgroundColor = "0 0 0 0.9",
120                      TextColor = "255 255 255 0.5",
121                      Anchor = new Anchor
122                      {
123                          Min = "0 0.944",
124                          Max = "1 1"
125                      },
126                      ELParent = MainLayer,
127                      ELName = MainLayer + ".PanelNameServer",
128                      Font = "robotocondensed-bold.ttf",
129                      FontSize = 22;
130                  }
131                  _CuiAvatarSetting = new CuiAvatarSetting
132                  {
133                      BackgroundColor = "0 0 0 0.9",
134                      TextColor = "255 255 255 0.5",
135                      Anchor = new Anchor
136                      {
137                          Min = "0.25 0.542",
138                          Max = "0.352 0.764"
139                      },
140                      ELParent = MainLayer,
141                      ELName = MainLayer = ".Avatar",
142                      ELNameImage = MainLayer = ".AvatarImage",
143                      ELNameText = MainLayer = ".AvatarText",
144                      Font = "robotocondensed-bold.ttf",
145                      FontSize = 20
146                  }
147  
148                  _CuiUButtonSetting = new List<CuiUButtonSetting>()
149                  {
150                      new CuiUButtonSetting
151                      {
152                          BackgroundColor = "0 0 0 0.9",
153                          SmallBackgroundColor = "255 255 255 0.05",
154                          TextColor = "255 255 255 0.5",
155                          ELParent = MainLayer,
156                          ELName = MainLayer + ".StandardButton",
157                          ELSmallName = MainLayer + ".StandardButtonSmallText",
158                          Font = "robotocondensed-bold.ttf",
159                          FontSize = 20,
160                          FontSizeSmall = 12,
161                          Anchor = new Anchor
162                          {
163                              Min = "0.25 0.465",
164                              Max = "0.352 0.535"
165                          },
166                          SmallText = "OPEN",
167                          Text = "STATISTICS",
168                          Command = "chat.say /test"
169                      },
170                      new CuiUButtonSetting
171                      {
172                          BackgroundColor = "0 0 0 0.9",
173                          SmallBackgroundColor = "255 255 255 0.05",
174                          TextColor = "255 255 255 0.5",
175                          ELParent = MainLayer,
176                          ELName = MainLayer + ".StandardButton",
177                          ELSmallName = MainLayer + ".StandardButtonSmallText",
178                          Font = "robotocondensed-bold.ttf",
179                          FontSize = 20,
180                          FontSizeSmall = 12,
181                          Anchor = new Anchor
182                          {
183                              Min = "0.25 0.389",
184                              Max = "0.352 0.458"
185                          },
186                          SmallText = "ACCEPT",
187                          Text = "TELEPORT",
188                          Command = "chat.say /test"
189                      },
190                      new CuiUButtonSetting
191                      {
192                          BackgroundColor = "0 0 0 0.9",
193                          SmallBackgroundColor = "255 255 255 0.05",
194                          TextColor = "255 255 255 0.5",
195                          ELParent = MainLayer,
196                          ELName = MainLayer + ".StandardButton",
197                          ELSmallName = MainLayer + ".StandardButtonSmallText",
198                          Font = "robotocondensed-bold.ttf",
199                          FontSize = 20,
200                          FontSizeSmall = 12,
201                          Anchor = new Anchor
202                          {
203                              Min = "0.25 0.313",
204                              Max = "0.352 0.382"
205                          },
206                          SmallText = "ACCEPT",
207                          Text = "TRADE",
208                          Command = "chat.say /test"
209                      },
210                      new CuiUButtonSetting
211                      {
212                          BackgroundColor = "0 0 0 0.9",
213                          SmallBackgroundColor = "255 255 255 0.05",
214                          TextColor = "255 255 255 0.5",
215                          ELParent = MainLayer,
216                          ELName = MainLayer + ".StandardButton",
217                          ELSmallName = MainLayer + ".StandardButtonSmallText",
218                          Font = "robotocondensed-bold.ttf",
219                          FontSize = 20,
220                          FontSizeSmall = 12,
221                          Anchor = new Anchor
222                          {
223                              Min = "0.25 0.236",
224                              Max = "0.352 0.306"
225                          },
226                          SmallText = "OPEN",
227                          Text = "WIPE BLOCK",
228                          Command = "chat.say /test"
229                      },
230                      new CuiUButtonSetting
231                      {
232                          BackgroundColor = "0 0 0 0.9",
233                          SmallBackgroundColor = "255 255 255 0.05",
234                          TextColor = "255 255 255 0.5",
235                          ELParent = MainLayer,
236                          ELName = MainLayer + ".StandardButton",
237                          ELSmallName = MainLayer + ".StandardButtonSmallText",
238                          Font = "robotocondensed-bold.ttf",
239                          FontSize = 20,
240                          FontSizeSmall = 12,
241                          Anchor = new Anchor
242                          {
243                              Min = "0.355 0.694",
244                              Max = "0.457 0.764"
245                          },
246                          SmallText = "OPEN",
247                          Text = "KITS",
248                          Command = "chat.say /test"
249                      },
250                      new CuiUButtonSetting
251                      {
252                          BackgroundColor = "0 0 0 0.9",
253                          SmallBackgroundColor = "255 255 255 0.05",
254                          TextColor = "255 255 255 0.5",
255                          ELParent = MainLayer,
256                          ELName = MainLayer + ".StandardButton",
257                          ELSmallName = MainLayer + ".StandardButtonSmallText",
258                          Font = "robotocondensed-bold.ttf",
259                          FontSize = 20,
260                          FontSizeSmall = 12,
261                          Anchor = new Anchor
262                          {
263                              Min = "0.355 0.618",
264                              Max = "0.457 0.688"
265                          },
266                          SmallText = "OPEN",
267                          Text = "CASES",
268                          Command = "chat.say /test"
269                      },
270                      new CuiUButtonSetting
271                      {
272                          BackgroundColor = "0 0 0 0.9",
273                          SmallBackgroundColor = "255 255 255 0.05",
274                          TextColor = "255 255 255 0.5",
275                          ELParent = MainLayer,
276                          ELName = MainLayer + ".StandardButton",
277                          ELSmallName = MainLayer + ".StandardButtonSmallText",
278                          Font = "robotocondensed-bold.ttf",
279                          FontSize = 20,
280                          FontSizeSmall = 12,
281                          Anchor = new Anchor
282                          {
283                              Min = "0.355 0.542",
284                              Max = "0.457 0.611"
285                          },
286                          SmallText = "SEND",
287                          Text = "TICKET",
288                          Command = "chat.say /test"
289                      },
290                      new CuiUButtonSetting
291                      {
292                          BackgroundColor = "0 0 0 0.9",
293                          SmallBackgroundColor = "255 255 255 0.05",
294                          TextColor = "255 255 255 0.5",
295                          ELParent = MainLayer,
296                          ELName = MainLayer + ".StandardButton",
297                          ELSmallName = MainLayer + ".StandardButtonSmallText",
298                          Font = "robotocondensed-bold.ttf",
299                          FontSize = 20,
300                          FontSizeSmall = 12,
301                          Anchor = new Anchor
302                          {
303                              Min = "0.355 0.465",
304                              Max = "0.457 0.535"
305                          },
306                          SmallText = "OPEN",
307                          Text = "STORE",
308                          Command = "chat.say /test"
309                      },
310                      new CuiUButtonSetting
311                      {
312                          BackgroundColor = "0 0 0 0.9",
313                          SmallBackgroundColor = "255 255 255 0.05",
314                          TextColor = "255 255 255 0.5",
315                          ELParent = MainLayer,
316                          ELName = MainLayer + ".StandardButton",
317                          ELSmallName = MainLayer + ".StandardButtonSmallText",
318                          Font = "robotocondensed-bold.ttf",
319                          FontSize = 20,
320                          FontSizeSmall = 12,
321                          Anchor = new Anchor
322                          {
323                              Min = "0.355 0.389",
324                              Max = "0.457 0.458"
325                          },
326                          SmallText = "OPEN",
327                          Text = "INFO",
328                          Command = "chat.say /test"
329                      },
330                      new CuiUButtonSetting
331                      {
332                          BackgroundColor = "0 0 0 0.9",
333                          SmallBackgroundColor = "255 255 255 0.05",
334                          TextColor = "255 255 255 0.5",
335                          ELParent = MainLayer,
336                          ELName = MainLayer + ".StandardButton",
337                          ELSmallName = MainLayer + ".StandardButtonSmallText",
338                          Font = "robotocondensed-bold.ttf",
339                          FontSize = 20,
340                          FontSizeSmall = 12,
341                          Anchor = new Anchor
342                          {
343                              Min = "0.355 0.313",
344                              Max = "0.457 0.382"
345                          },
346                          SmallText = "OPEN",
347                          Text = "VK GROUP",
348                          Command = "chat.say /test"
349                      },
350                      new CuiUButtonSetting
351                      {
352                          BackgroundColor = "0 0 0 0.9",
353                          SmallBackgroundColor = "255 255 255 0.05",
354                          TextColor = "255 255 255 0.5",
355                          ELParent = MainLayer,
356                          ELName = MainLayer + ".StandardButton",
357                          ELSmallName = MainLayer + ".StandardButtonSmallText",
358                          Font = "robotocondensed-bold.ttf",
359                          FontSize = 20,
360                          FontSizeSmall = 12,
361                          Anchor = new Anchor
362                          {
363                              Min = "0.355 0.236",
364                              Max = "0.457 0.306"
365                          },
366                          SmallText = "OPEN",
367                          Text = "DISCORD",
368                          Command = "chat.say /test"
369                      }
370                  };
371              };
372          }
373  
374          private void SaveConfig()
375          {
376              Config.WriteObject(_config, true);
377          }
378  
379          #endregion
380  
381          #region Init
382  
383          void OnServerInitialized(bool serverInitialized)
384          {
385              _config = Config.ReadObject<PluginConfig>();
386          }
387  
388          #endregion
389  
390          #region CuiRustCustomHelper
391  
392          private static class CuiRustCustomHelper
393          {
394              public static CuiElementContainer GettingStandardElement(CuiStandardElementSetting _setting)
395              {
396                  var container = new CuiElementContainer();
397  
398                  container.Add(new CuiPanel
399                  {
400                      Image = { Color = "0 0 0 0" },
401                      RectTransform = { AnchorMin = _setting.Anchor.Min, AnchorMax = _setting.Anchor.Max },
402                      CursorEnabled = _setting.CursorEnabled,
403                  }, "Overlay", _setting.Layer);
404  
405                  container.Add(new CuiElement
406                  {
407                      Parent = LayerMain,
408                      Components =
409                      {
410                          new CuiRawImageComponent { Color = _setting.BackgroundColor, FadeIn = 0.5f, Sprite = "assets/content/ui/ui.background.tiletex.psd", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat" },
411                          new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = "1 1" }
412                      }
413                  });
414  
415                  return container;
416              }
417  
418              public static CuiElementContainer GettingServerNameElement(CuiServerNameSetting _setting)
419              {
420                  var container = new CuiElementContainer();
421  
422                  container.Add(new CuiElement
423                  {
424                      Parent = _setting.ELParent,
425                      Name = _setting.ELName,
426                      Components =
427                      {
428                          new CuiImageComponent { FadeIn = 0.25f, Color = _setting.BackgroundColor} ,
429                          new CuiRectTransformComponent { AnchorMin = _setting.Anchor.Min, AnchorMax = _setting.Anchor.Max }
430                      }
431                  });
432                  container.Add(new CuiElement
433                  {
434                      Parent = _setting.ELName,
435                      Components = {
436                          new CuiTextComponent() { Color = _setting.TextColor, FadeIn = 1f, Text = _setting.NameServer, FontSize = _setting.FontSize, Align = TextAnchor.MiddleCenter, Font = _setting.Font },
437                          new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
438                      }
439                  });
440  
441                  return container;
442              }
443  
444              public static CuiElementContainer GettingAvatarElement(BasePlayer player, CuiAvatarSetting _setting)
445              {
446                  var container = new CuiElementContainer();
447  
448                  container.Add(new CuiElement
449                  {
450                      Parent = _setting.ELParent,
451                      Name = _setting.ELName,
452                      Components =
453                      {
454                          new CuiImageComponent {FadeIn = 0.25f, Color = _setting.BackgroundColor},
455                          new CuiRectTransformComponent { AnchorMin = _setting.Anchor.Min, AnchorMax = _setting.Anchor.Max }
456                      }
457                  });
458                  container.Add(new CuiElement
459                  {
460                      Parent = _setting.ELName,
461                      Name = _setting.ELNameImage,
462                      Components =
463                      {
464                          new CuiImageComponent {FadeIn = 0.25f, Color = "0 0 0 0"},
465                          new CuiRectTransformComponent {AnchorMin = "0 0.188", AnchorMax = "1 1"}
466                      }
467                  });
468                  container.Add(new CuiElement
469                  {
470                      Parent = _setting.ELNameImage,
471                      Components =
472                      {
473                          new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", player.UserIDString) },
474                          new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0" }
475                      }
476                  });
477                  container.Add(new CuiElement
478                  {
479                      Parent = _setting.ELName,
480                      Name = _setting.ELNameText,
481                      Components =
482                      {
483                          new CuiImageComponent {FadeIn = 0.25f, Color = "0 0 0 0"},
484                          new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 0.188"}
485                      }
486                  });
487                  container.Add(new CuiElement
488                  {
489                      Parent = _setting.ELNameText,
490                      Components = {
491                          new CuiTextComponent() { Color = _setting.TextColor, FadeIn = 1f, Text = ""+player.displayName.ToUpper()+"", FontSize = _setting.FontSize, Align = TextAnchor.MiddleCenter, Font = _setting.Font },
492                          new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
493                      }
494                  });
495  
496                  return container;
497              }
498  
499              public static CuiElementContainer GettingButtonElement(BasePlayer player, List<CuiUButtonSetting> _setting)
500              {
501                  var container = new CuiElementContainer();
502  
503                  foreach (var _settingItem in _setting)
504                  {
505                      container.Add(new CuiElement
506                      {
507                          Parent = _settingItem.ELParent,
508                          Name = _settingItem.ELName,
509                          Components = {
510                              new CuiImageComponent {FadeIn = 0.25f, Color = _settingItem.BackgroundColor},
511                              new CuiRectTransformComponent {AnchorMin = _settingItem.Anchor.Min, AnchorMax = _settingItem.Anchor.Max}
512                          }
513                      });
514                      container.Add(new CuiButton
515                      {
516                          RectTransform = { AnchorMin = "0 0", AnchorMax = "1 0.7" },
517                          Button = { Command = _settingItem.Command, Close = _settingItem.ELParent, Color = "0 0 0 0" },
518                          Text = { Color = _settingItem.TextColor, Text = _settingItem.Text, FontSize = _settingItem.FontSize, Align = TextAnchor.MiddleCenter, Font = _settingItem.Font }
519                      }, _settingItem.ELName);
520                      container.Add(new CuiElement
521                      {
522                          Parent = _settingItem.ELName,
523                          Name = _settingItem.ELSmallName,
524                          Components = {
525                              new CuiImageComponent {FadeIn = 0.25f, Color = _settingItem.SmallBackgroundColor},
526                              new CuiRectTransformComponent {AnchorMin = "0 0.7", AnchorMax = "1 1"}
527                          }
528                      });
529                      container.Add(new CuiElement
530                      {
531                          Parent = _settingItem.ELSmallName,
532                          Components = {
533                              new CuiTextComponent() {Color = _settingItem.TextColor, FadeIn = 1f, Text = _settingItem.SmallText, FontSize = _settingItem.FontSize, Align = TextAnchor.MiddleCenter, Font = _settingItem.Font},
534                              new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 1"}
535                          }
536                      });
537                  }
538  
539                  return container;
540              }
541          }
542  
543          #endregion
544  
545          #region UI
546  
547          private void CustomDrawCUI(BasePlayer player)
548          {
549              CuiHelper.AddUi(player, GettingStandardElement(_config._CuiStandardElementSetting)); 
550              CuiHelper.AddUi(player, GettingServerNameElement(_config._CuiServerNameSetting)); 
551              CuiHelper.AddUi(player, GettingAvatarElement(player, _config._CuiAvatarSetting)); 
552              CuiHelper.AddUi(player, GettingButtonElement(player, _config._CuiUButtonSetting)); 
553          }
554  
555          private void CustomDestroyCUI(BasePlayer player)
556          {
557              CuiHelper.DestroyUi(player, MainLayer);
558          }
559  
560          #endregion
561  
562          #region Hook
563  
564          [ChatCommand("menu")]
565          private void ChatOpenMenu(BasePlayer player)
566          {
567              CustomDrawCUI(player);
568          }
569  
570          [ChatCommand("menu.close")]
571          private void ChatCloseMenu(BasePlayer player)
572          {
573              CustomDestroyCUI(player);
574          }
575  
576          [ConsoleCommand("skymenu.open")]
577          private void CmdOpenMenu(BasePlayer player)
578          {
579              CustomDrawCUI(player);
580          }
581  
582          [ConsoleCommand("skymenu.close")]
583          private void CmdCloseMenu(BasePlayer player)
584          {
585              CustomDestroyCUI(player);
586          }
587  
588          #endregion
589      }
590  }

What I have tried:

I can’t figure out how to deal with this error

Gde

0 / 0 / 0

Регистрация: 13.04.2020

Сообщений: 9

1

04.12.2020, 09:32. Показов 7194. Ответов 5

Метки нет (Все метки)


Выскакивает ошибка main.cs(17,11): error CS1525: Unexpected symbol `void’, expecting `class’, `delegate’, `enum’, `interface’, `partial’, or `struct’. Не подскажите из-за чего?

C#
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
enum TravEn
{
    Север = 11,
    Запад = 12,
    Юг = 13,
    Восток = 14,
    Неопределенно = 100
}
 
enum CommEn
    {
        Продолжить = 0,
        Налево = 1,
        Направо = -1,
        Неопределенно = 100
    }
    static void Main(string[] args)
    {
        TravEn trav = TravEn.Неопределенно; // направление
        Console.Write(" Введите начальное направление движения: ");
        while (trav == TravEn.Неопределенно)
        {
            string inp = Console.ReadLine();
            int inpInt = 0;
            if (int.TryParse(inp, out inpInt) && Enum.IsDefined(typeof(TravEn), inpInt))
                trav = (TravEn)inpInt;
            else
                Console.Write(" Ошибка ввода! rn Введите ещё раз начальное направление движения: ");
        }
        Console.WriteLine($" Начальное направление движения: {trav.ToString()}");
 
        CommEn comm = CommEn.Неопределенно; // команда
        Console.Write(" Enter в пустой сроке -> Выход ");
        do
        {
            Console.Write(" Введите команду: ");
            while (comm == CommEn.Неопределенно)
            {
                string inp = Console.ReadLine();
                int inpInt = 0;
                if (int.TryParse(inp, out inpInt) && Enum.IsDefined(typeof(CommEn), inpInt))
                    comm = (CommEn)inpInt;
                else if (!string.IsNullOrWhiteSpace(inp))
                    Console.Write(" Ошибка ввода! rn Введите ещё раз команду: ");
                else
                    break;
            }
            if (!(comm == CommEn.Неопределенно))
            {
                switch (comm)
                {
                    case CommEn.Налево:
                        switch (trav)
                        {
                            case TravEn.Север: trav = TravEn.Запад; break;
                            case TravEn.Запад: trav = TravEn.Юг; break;
                            case TravEn.Юг: trav = TravEn.Восток; break;
                            case TravEn.Восток: trav = TravEn.Север; break;
                        }
                        break;
 
                    case CommEn.Направо:
                        switch (trav)
                        {
                            case TravEn.Север: trav = TravEn.Восток; break;
                            case TravEn.Запад: trav = TravEn.Север; break;
                            case TravEn.Юг: trav = TravEn.Запад; break;
                            case TravEn.Восток: trav = TravEn.Юг; break;
                        }
                        break;
                }
                Console.WriteLine($" Команда: {comm.ToString()}, направление движения: {trav.ToString()}");
                comm = CommEn.Неопределенно;
            }
            else
            {
                Console.WriteLine(" Выход из программы!");
                Console.WriteLine($" Конечное направление движения: {trav.ToString()}");
                Console.WriteLine(" Нажмите любую клавишу ..........");
                Console.ReadKey();
                return;
            }
        }    
    } while (true);

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Programming

Эксперт

94731 / 64177 / 26122

Регистрация: 12.04.2006

Сообщений: 116,782

04.12.2020, 09:32

Ответы с готовыми решениями:

Error: Expected class, delegate, enum, interface, or struct
Создал приложение winforms, добавил класс с реализацией методов, почему то куча ошибок типа…

ошибка CS1519 unexpected symbol 0.2 in class, stuct or interface member declaration
Насцене 2 объекта, один terrain другой претащенный из Project assets авто. Ставлю на авто этот…

Ошибка в скрипте Unity: Unexpected symbol in class, struct, or interface member declaration
ОШИБА в 6 строке
using System.Collections;
using System.Collections.Generic;
using UnityEngine;…

Ошибки в коде — Expected class, delegate, enum, interface, or struct
С с# не знаком, полез на msdn.microsoft.com насчет ошибок, тоже не очень понятно. насчет cs1513…

5

управление сложностью

1687 / 1300 / 259

Регистрация: 22.03.2015

Сообщений: 7,545

Записей в блоге: 5

04.12.2020, 09:34

2

Цитата
Сообщение от Gde
Посмотреть сообщение

Не подскажите из-за чего?

Копипастить нужно аккуратнее.



0



0 / 0 / 0

Регистрация: 13.04.2020

Сообщений: 9

04.12.2020, 09:52

 [ТС]

3

Если язык сложно понять, а работу нужно сдать поскорее, ничего больше не остаётся. Если увидели такое, не надо помои на человека выливать. Лучше не пишите вообще



0



управление сложностью

1687 / 1300 / 259

Регистрация: 22.03.2015

Сообщений: 7,545

Записей в блоге: 5

04.12.2020, 09:55

4

Gde, я вам указал на ошибку, этого не достаточно ?



0



35 / 20 / 15

Регистрация: 04.08.2020

Сообщений: 64

04.12.2020, 12:05

5

Лучший ответ Сообщение было отмечено Gde как решение

Решение

У вас условие цикла do while проверяется вне Main, перенесите обратно



0



OwenGlendower

Администратор

Эксперт .NET

15248 / 12287 / 4904

Регистрация: 17.03.2014

Сообщений: 24,884

Записей в блоге: 1

04.12.2020, 12:33

6

Лучший ответ Сообщение было отмечено Gde как решение

Решение

Gde, я так понимаю это весь код и значит нужно поместить Main в класс. Ведь в C# не существует т.н. свободных методов. Ну и сделать что Gagik1 посоветовал тоже нужно. После этого код откомпилируется.

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
enum TravEn
{
    Север = 11,
    Запад = 12,
    Юг = 13,
    Восток = 14,
    Неопределенно = 100
}
 
enum CommEn
{
    Продолжить = 0,
    Налево = 1,
    Направо = -1,
    Неопределенно = 100
}
 
class Program
{
    static void Main(string[] args)
    {
        // Тело Main ...
    }
}

Добавлено через 1 минуту
Хотя еще using-ы понадобятся в начале файла.

C#
1
using System;

Добавлено через 2 минуты

Цитата
Сообщение от Почтальон
Посмотреть сообщение

я вам указал на ошибку, этого не достаточно ?

Вы написали правильный, но совершенно бесполезный ответ. Поэтому да — «Лучше не пишите вообще».



0



IT_Exp

Эксперт

87844 / 49110 / 22898

Регистрация: 17.06.2006

Сообщений: 92,604

04.12.2020, 12:33

Помогаю со студенческими работами здесь

Ошибка «Unexpected symbol in class, struct, or interface member declaration»
Unity выдаёт ошибку: Assets/Scripts/Item.cs(11,36): error CS1519: Unexpected symbol `ItemType’ in…

Parse error: syntax error, unexpected ‘class’ (T_CLASS), expecting function (T_FUNCTION)
ошибка
Parse error: syntax error, unexpected ‘class’ (T_CLASS), expecting function (T_FUNCTION)…

Ошибка— class, interface, or enum expected
В таком коде (хотя много подобных ошибок):
public void dosomething() {
int x;

Ошибка Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRIN
При запуске локального сервера, выдает эту ошибку.
Parse error: syntax error, unexpected…

Ошибка Parse error: syntax error, unexpected ‘=’, expecting ‘,’ or ‘;’ in /inc_db.php on
global $db = mysqli_connect(‘localhost’,’———‘,’————‘)or die(mysql_error());…

В чем ошибка (Parse error: syntax error, unexpected ‘$i’ (T_VARIABLE), expecting ‘;’) ?
private function select($table_name,$fields,$where=&quot;&quot;,$order=&quot;&quot;,$up=true,$limit=&quot;&quot;)
{…

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:

6

Содержание

  1. C# error CS1525: Unexpected symbol `>’
  2. 2 Answers
  3. Your program «works», but deviates from the instructions.

C# error CS1525: Unexpected symbol `>’

I am sure that every «<» has its equally paired «>» in my code, but the compiler keep telling me that Program.cs(20,40): error CS1525: Unexpected symbol `>’. I wonder where my mistake is, and how can I fix it?

2 Answers

Steven Parker
Steven Parker

Your program «works», but deviates from the instructions.

This is a great example of how something that works (will compile an run) might not be what was asked for (satisfies the requirements). This has been a topic of many previous questions, but I’ll repost the info here:

People often over-think this one and get too creative, and their answer is rejected for a variety of reasons (some which don’t seem to make any sense).

Here are the secret «rules» you must follow for success on this one:

  • Your program must ask for and accept input ONE TIME ONLY
  • If the input validates, your program will perform exactly as in Task 1
  • If the input does not validate, it will print the error message and exit
  • Validation must be done by exception catching. There are other perfectly good methods that can be used for validation, but they will not pass this challenge

It looks like you have an extra loop that is violating the first and third «rule».

Источник

It’s just a syntax problem, as you forgot to close the scope.

Working:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Solution
{
    static void Main(string[] args)
    {
        int simpleArraySum(int[] ar)
        {
            int sum = 0;
            for (int i = 0; i < ar.Length; i++)
            {
                sum = sum + ar[i];
            }

            return sum;
        }

        Console.WriteLine(simpleArraySum(new int[] { 1, 2, 3 }));
    }
}

Added a ‘}’ at the end to close the scope, and added a Console.WriteLine to show the function’s return.


Update

As some comments pointed out, you would need C# 7.1 + to use a method inside another. If you don’t have this compiler version, you could try taking the method out of the Main, like this:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Program
{
    static int simpleArraySum(int[] ar)
    {
        int sum = 0;
        for (int i = 0; i < ar.Length; i++)
        {
            sum = sum + ar[i];
        }

        return sum;
    }

    static void Main(string[] args)
    {
        Console.WriteLine(simpleArraySum(new int[] { 1, 2, 3 }));
    }
}

Before:

| static void Main
|____ int simpleArraySum(int[])
|____ calls simpleArraySum which is in scope

After:

| static int simpleArraySum(int[])
| static void Main
|____ calls simpleArraySum which is a static method

  • Remove From My Forums
  • Question

  • Hi. I have a Homework, practically 100% similar to the one found  here (Link missing as THey need to verify my account, please do so I can post a link.)

    Code goes like this

    private void Form1_Load(object sender, EventArgs e)
            {
                List<TreeNode> allNodes = new List<TreeNode>();
                using (StreamReader sr = new StreamReader("NodeList.txt"))
                {
                    while (!sr.EndOfStream)
                    {
                        string str = sr.ReadLine();
                        Regex regex = new Regex(@"(w.*?)((.*?))");
                        Match match = regex.Match(str);
                        if (match.Success)
                        {
                            string nodeText = match.Groups[1].Value;
                            string nodeId_parentId = match.Groups[2].Value;
                            string nodeId = nodeId_parentId.Contains(',') ? nodeId_parentId.Split(',')[0] : nodeId_parentId;
                            string parentId = nodeId_parentId.Contains(',') ? nodeId_parentId.Split(',')[1] : null;
    
                            TreeNode node = new TreeNode();
                            node.Text = nodeText; //NodeText
                            node.ToolTipText = nodeId; //As TreeNode class doesn't contain a property named NodeId, I store the id with this property
                            node.Tag = parentId; //ParentId
                            allNodes.Add(node);
                        }
                    }
                }
    
                TreeNode currentNode = allNodes.FindAll(n => n.Tag == null).FirstOrDefault();
                AppendChildNodes(currentNode, allNodes);
                this.treeView1.Nodes.Add(currentNode);
            }
    
            private void AppendChildNodes(TreeNode currentNode,List<TreeNode> allNodes)
            {
                currentNode.Nodes.AddRange(allNodes.FindAll(n => (n.Tag!=null) && (n.Tag.ToString() == currentNode.ToolTipText)).ToArray());
                foreach (TreeNode node in currentNode.Nodes)
                {
                    AppendChildNodes(node, allNodes);
                }
            }

    I copy/pasted the code. However, when I try to start/compile the code Proposed as answer by Cor Ligthert

    I get an error    : «error CS1525: Unexpected symbol `void’, expecting `class’, `delegate’, `enum’, `interface’, `partial’, or `struct'»

    I did name the Text file NodeList.txt, (same as given in code).

    «NodeList.txt»

    But I guess I am missing something noobish here, as this is the first time I am working with C# at all.

    • Edited by

      Monday, January 15, 2018 9:38 PM

    • Moved by
      CoolDadTx
      Tuesday, January 16, 2018 2:53 PM
      Winforms related

Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Li Yu

I am sure that every «{» has its equally paired «}» in my code, but the compiler keep telling me that Program.cs(20,40): error CS1525: Unexpected symbol `}’.
I wonder where my mistake is, and how can I fix it?


Program.cs

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            while(true)  //loop started
            {
                Console.Write("Enter the number of times to print "Yay!": ");
                string entry = Console.ReadLine();

                    if(entry.ToLower()=="quit")
                    {
                        break;
                    }
                    else
                    {
                        int time = int.Parse(entry);  //turn "string" into "int"
                        int k;
                        for(k = 0; k < time)  //make the loop run k times
                        {
                            Console.Write("Yay!");
                            k = k + 1;
                            continue;
                        }    
                    }

                break;  //leave the "while loop" since "for" is not satisfied
            }    
        }
    }
}

2 Answers

Steven Parker

:point_right: Your program «works», but deviates from the instructions.

This is a great example of how something that works (will compile an run) might not be what was asked for (satisfies the requirements). This has been a topic of many previous questions, but I’ll repost the info here:

People often over-think this one and get too creative, and their answer is rejected for a variety of reasons (some which don’t seem to make any sense).

Here are the secret «rules» you must follow for success on this one:

  • Your program must ask for and accept input ONE TIME ONLY
  • If the input validates, your program will perform exactly as in Task 1
  • If the input does not validate, it will print the error message and exit
  • Validation must be done by exception catching. There are other perfectly good methods that can be used for validation, but they will not pass this challenge

It looks like you have an extra loop that is violating the first and third «rule».

Avan Sharma

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
                              Console.Write("Enter the number of times to print "Yay!": ");
                                    int entry = int.Parse(Console.ReadLine());
                            for(int i=0;i<entry;i++)
                           {
                                 Console.WriteLine("Yay!");
                            }
         }
    }
}

Понравилась статья? Поделить с друзьями:
  • Error cs1525 unexpected symbol end of file
  • Error cs1525 invalid expression term unity
  • Error cs1525 invalid expression term string
  • Error cs1525 invalid expression term int
  • Error cs1520 method must have a return type unity