Question

Write a method called Drawline that accepts as input an integer n and generates a line...

Write a method called Drawline that accepts as input an integer n and generates a line of output in lstOutput with n hyphens. That is, if n = 6 we have a line of ‘------‘ displayed in the list box.

Must be in C#

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per requirement submitted above kindly find below solution.

Here new windows forms application in C# is created using visual studio 2019 with name "SimpleCSharpApp". This application contains a form with name "Form1.cs".Below is the details of this form.

Form1.cs[Design] :

Draw line . x Enter number: 0 Draw Line

**********************************

Form1.cs :

//namespace
using System;
using System.Windows.Forms;
//application namespace
namespace SimpleCSharpApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Drawline button click
private void btnDrawLine_Click(object sender, EventArgs e)
{
//taking number entered by user
int number = int.Parse(txtNumber.Text);
//call method
this.Drawline(number);
}
//method to drawline
public void Drawline(int n)
{
string line = "";//declaring variable to generate line
//using for loop
for (int i = 0; i < n; i++)
{
//concatenate hypens
line = line + "-";
}
//show line in the listbox
lstOutput.Items.Add(line);
}
}
}

==================================

Output :Run application using F5 and will get the screen as shown below

Screen 1:Form1.cs

Draw line . x Enter number: 0 Draw Line

Screen 2:Screen showing line in the list box when a numnber with value 6 is entered

Draw line - O X Enter number: Draw Line

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Write a method called Drawline that accepts as input an integer n and generates a line...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT