C
C#3mo ago
M7

Newbie tryna learn help with Console app

Hey im learning and need some assistance with this little detail would do good for me
30 Replies
Angius
Angius3mo ago
Just ask
M7
M73mo ago
i would like the text on the Console app text to apppear character by character letter by letter heres the base im working off
using System;

class Program
{
static void Main(string[] args)
{
bool showMenu = true;

while (showMenu)
{
showMenu = MainMenu();
}
}

static bool MainMenu()
{
Console.Clear();
Console.WriteLine("Testing Testing Testing");
Console.WriteLine("1) Option 1");
Console.WriteLine("2) Option 2");
Console.WriteLine("3) Exit");
Console.Write("\r\nSelect an option: ");

switch (Console.ReadLine())
{
case "1":
Console.WriteLine("You selected Option 1");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
return true;
case "2":
Console.WriteLine("You selected Option 2");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
return true;
case "3":
return false;
default:
return true;
}
}
}
using System;

class Program
{
static void Main(string[] args)
{
bool showMenu = true;

while (showMenu)
{
showMenu = MainMenu();
}
}

static bool MainMenu()
{
Console.Clear();
Console.WriteLine("Testing Testing Testing");
Console.WriteLine("1) Option 1");
Console.WriteLine("2) Option 2");
Console.WriteLine("3) Exit");
Console.Write("\r\nSelect an option: ");

switch (Console.ReadLine())
{
case "1":
Console.WriteLine("You selected Option 1");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
return true;
case "2":
Console.WriteLine("You selected Option 2");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
return true;
case "3":
return false;
default:
return true;
}
}
}
basically need the "testing testing testing" to appear letter by letter
Angius
Angius3mo ago
A loop would, no doubt, be useful here And make use of the fact that a string is really just an array of characters
M7
M73mo ago
im learning as i start a project could you possibly give me some more insight?
Angius
Angius3mo ago
Foreach over the string you want to print and print each character separately, one by one
M7
M73mo ago
idk how to do that im sorry i read 2 threads on the fact and attempted to implement the suggestions into my project didnt seem to work
Angius
Angius3mo ago
$helloworld
Angius
Angius3mo ago
You have a while loop so you know what a loop is foreach is another kind of a loop And a string "hello" is the same as an array of characters ['h', 'e', 'l', 'l', 'o'] Console.Write() can write without adding a new line Combine those three elements
M7
M73mo ago
dont get mad i got help of AI to get started with simple code
Angius
Angius3mo ago
Ah, well, don't Learn
M7
M73mo ago
?
Angius
Angius3mo ago
If you want to learn programming, learn to write the code yourself instead of generating it with an LLM Same principle as "if you want to learn how to draw, pick up the pencil instead of using Stable Diffusion" The LLM will generate code, and you will have no clue what it did
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
M7
M73mo ago
was just tryna learn via throwing myself into somethin
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Angius
Angius3mo ago
Learning by doing is great!
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Angius
Angius3mo ago
It implies "doing" tho
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
M7
M73mo ago
so im tryna under stand how the "for each" wirks
static void TypeText(string text)
{
foreach (Char c in text)
{
Console.Write(c);
Thread.Sleep(100); // Adjust the sleep duration to change the speed
}
}
static bool MainMenu()
{
Console.Clear();
TypeText("Testing Testing Testing\n");
static void TypeText(string text)
{
foreach (Char c in text)
{
Console.Write(c);
Thread.Sleep(100); // Adjust the sleep duration to change the speed
}
}
static bool MainMenu()
{
Console.Clear();
TypeText("Testing Testing Testing\n");
i dont see why this wont work
Angius
Angius3mo ago
What doesn't work about it?
M7
M73mo ago
doesnt send letter by letter
Angius
Angius3mo ago
Works for me
No description
Angius
Angius3mo ago
Try higher delay so it's more noticeable maybe?
M7
M73mo ago
how could i do partial millicseconds like less then 1 ms
Angius
Angius3mo ago
That delay would be imperceptible for a human Around 200ms is the edge of human perception
M7
M73mo ago
idk its on 1ms and its not that fast... myabe my pc is just slow rn
Angius
Angius3mo ago
In my gif, that's the 100ms speed
Angius
Angius3mo ago
Same if we do it asynchronously
No description
Want results from more Discord servers?
Add your server
More Posts