& I wanna create text file containing one name on each line. Compute the number of times any name occurs. Output one line for each name in file and on each line print the number of occurrences followed by name.
and display the result in MessegeBox.Show
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
& public Form1()
& {
InitializeComponent();
& }
& private void button1_Click(object sender, EventArgs e)
& {
string[] names = richTextBox1.Text.Split('\n');
List<string> newNames = new List<string>();
List<int> newNamesIndex = new List<int>();
&
for (int i = 0; i < names.Length; i++)
{
int k = 0;
for (int j = 0; j < newNames.Count; j++)
{
& if (newNames[j] != names[i])
& {
k++;
& }
& else
& {
newNamesIndex[j]++;
& }
}
if (k == newNames.Count)
{
& newNames.Add(names[i]);
& newNamesIndex.Add(1);
}
}
richTextBox1.Clear();
for (int i = 0; i < newNames.Count; i++)
{
richTextBox1.Text += newNames[i] + " " + newNamesIndex[i] + "\n";
}
& }
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C#