© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
9 replies
Redoxi

Why does this not work? [Answered]

Hey, pretty new to coding and trying some things out, someone knows why it says that my var "randomNumber" is not in the context?
using System;

namespace Awesome_Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Typewriter("Hello... Wizard!");
        }

        public static int NumberGen()
        {
            Random numberGen = new Random();
            int number = numberGen.Next(50,300); 
        }

        public static void Typewriter(string word)
        {
           for (int i = 0; i < word.Length; i++)
           {
                Console.Write(word[i]);
                int randomNumber = NumberGen();
                System.Threading.Thread.Sleep(randomNumber);
           } 
        }
    }
}
using System;

namespace Awesome_Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Typewriter("Hello... Wizard!");
        }

        public static int NumberGen()
        {
            Random numberGen = new Random();
            int number = numberGen.Next(50,300); 
        }

        public static void Typewriter(string word)
        {
           for (int i = 0; i < word.Length; i++)
           {
                Console.Write(word[i]);
                int randomNumber = NumberGen();
                System.Threading.Thread.Sleep(randomNumber);
           } 
        }
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

why does this Not work?
C#CC# / help
3y ago
❔ Why does this not work?
C#CC# / help
3y ago
❔ ✅ Why does this not work???
C#CC# / help
3y ago
why does this code not work???
C#CC# / help
3w ago