1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
andreyandreev [35.5K]
3 years ago
6

Write C# program that will read name from keyboard and display it on screen. The program should throw an exception when the leng

th of name is more than 15 character.
Computers and Technology
1 answer:
Hitman42 [59]3 years ago
4 0

Answer:

       static void Main(string[] args)

       {

           try

           {

               Console.Write("Enter your name: ");

               string name = Console.ReadLine();

               if (name.Length > 15)

               {

                   throw new Exception($"Name length {name.Length} is too long, max 15!");

               }

               else

               {

                   Console.WriteLine("Hello " + name);

               }

           }  

           catch(Exception ex)

           {

               Console.WriteLine("Exception occurred: " + ex.Message);

           }

       }

Explanation:

This is one way of doing it. More elaborate is to subclass Exception into NameLengthException and throw that.

You might be interested in
What's a False statement about online time? A. Blue light from devices can make it hard to sleep. B. It's a good way to connect
mylen [45]

Answer:C

Explanation: This has no basis while the others have studied behind them.

4 0
4 years ago
Please help me i’ll give you brainlist
Genrish500 [490]

answer: C

explanation: because it's the biggest of the given platforms

5 0
3 years ago
What shooting position is commonly used when hunting with a shotgun?
amid [387]
Standing well for me I never miss a shot in that position

6 0
4 years ago
Read 2 more answers
To create a query string, you add a ____ immediately after a url, followed by the query string.
salantis [7]
The answer is question mark (?).  To create a query string, you add a question mark (?) immediately after a url, followed by the query string.
5 0
3 years ago
0.6 tenths of an hour would be how many minutes?
astraxan [27]

Answer:

17 min bro

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following makes videos appear smoother and more fluid?
    9·2 answers
  • Which of the following devices electronically sorts mail by ZIP code? A. Fax modem B. Electronic organizer C. Optical character
    10·1 answer
  • Households pay taxes to the government and receive public services. Which of the following is a public service?
    8·1 answer
  • Obtain a file name from the user, which will contain data pertaining to a 2D array Create a file for each of the following: aver
    5·1 answer
  • To give text an outline, you can use which command?
    15·1 answer
  • Select the correct answer.
    10·2 answers
  • Private sharing model on Opportunities. Leadership has asked the Administrator to create a new custom object that will track cus
    7·1 answer
  • Select the correct answer.
    14·1 answer
  • Why computer is known as versatile and diligent device? Explain​
    7·1 answer
  • Question # 4
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!