C
C#ā€¢10mo ago
js

need help with a console menu

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Summative8.Menu
{
internal abstract class ConsoleMenu : MenuItem
{
protected List<MenuItem> _menuItems = new List<MenuItem>();

public bool IsActive { get; set; }

public abstract void CreateMenu();

public override void Select()
{
IsActive = true;
do
{
CreateMenu();
string output = $"{MenuText()}{Environment.NewLine}";
int selection = ConsoleHelpers.GetIntegerInRange(1, _menuItems.Count, this.ToString()) - 1;
_menuItems[selection].Select();
} while (IsActive);
}

public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(MenuText());
for (int i = 0; i < _menuItems.Count; i++)
{
sb.AppendLine($"{i + 1}. {_menuItems[i].MenuText()}");
}
return sb.ToString();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Summative8.Menu
{
internal abstract class ConsoleMenu : MenuItem
{
protected List<MenuItem> _menuItems = new List<MenuItem>();

public bool IsActive { get; set; }

public abstract void CreateMenu();

public override void Select()
{
IsActive = true;
do
{
CreateMenu();
string output = $"{MenuText()}{Environment.NewLine}";
int selection = ConsoleHelpers.GetIntegerInRange(1, _menuItems.Count, this.ToString()) - 1;
_menuItems[selection].Select();
} while (IsActive);
}

public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(MenuText());
for (int i = 0; i < _menuItems.Count; i++)
{
sb.AppendLine($"{i + 1}. {_menuItems[i].MenuText()}");
}
return sb.ToString();
}
}
}
ive no errors in all the classes I have created other than this line, and I am struggling to see what I have done wrong
int selection = ConsoleHelpers.GetIntegerInRange(1, _menuItems.Count, this.ToString()) - 1;
int selection = ConsoleHelpers.GetIntegerInRange(1, _menuItems.Count, this.ToString()) - 1;
No description
13 Replies
js
jsOPā€¢10mo ago
my lecturer always uses this consolehelper thing and i dont understand what it does or how i am supposed to use it
Jimmacle
Jimmacleā€¢10mo ago
it's not a standard thing it's either a nuget package or a class he wrote himself
js
jsOPā€¢10mo ago
what could i use instead of that to get an int in range
Jimmacle
Jimmacleā€¢10mo ago
you could write your own helper method i don't know if that's what your lecturer intends though, did you ask them?
js
jsOPā€¢10mo ago
idk i missed a couple of lectures cause of health issues and im trying to do stuff that i havent seen explained
Jimmacle
Jimmacleā€¢10mo ago
ask them or one of your classmates, we can't know what you're supposed to be doing here
js
jsOPā€¢10mo ago
literally the most basic menu selecting a number from a list of options in a console menu
Angius
Angiusā€¢10mo ago
We have no way of knowing what ConsoleHelper does
js
jsOPā€¢10mo ago
ohh
Angius
Angiusā€¢10mo ago
It seems like ConsoleHelpers.GetIntegerInRange() would be getting user input, parsing it to an integer, and checking if it's within the specified range
js
jsOPā€¢10mo ago
yh its just a basic assignment with shape classes and editing shape properties etc
Jimmacle
Jimmacleā€¢10mo ago
right, but we don't know if your teacher expects you to write that class or if it was provided to you
js
jsOPā€¢10mo ago
im still first year ill watch lectures back and msg if i have any questions thanks for help šŸ™‚
Want results from more Discord servers?
Add your server