C
C#•14mo 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•14mo 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•14mo ago
it's not a standard thing it's either a nuget package or a class he wrote himself
js
jsOP•14mo ago
what could i use instead of that to get an int in range
Jimmacle
Jimmacle•14mo 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•14mo 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•14mo ago
ask them or one of your classmates, we can't know what you're supposed to be doing here
js
jsOP•14mo ago
literally the most basic menu selecting a number from a list of options in a console menu
Angius
Angius•14mo ago
We have no way of knowing what ConsoleHelper does
js
jsOP•14mo ago
ohh
Angius
Angius•14mo 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•14mo ago
yh its just a basic assignment with shape classes and editing shape properties etc
Jimmacle
Jimmacle•14mo 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•14mo ago
im still first year ill watch lectures back and msg if i have any questions thanks for help šŸ™‚

Did you find this page helpful?