سلام
سوال اول
خب میتونی بنویسی write با دستور n\ بره خط بعدی و یا writeline
خب سوال دوم برای این کار میبایستی 3 تا متغییر داشته باشی یا هرچند تا متغییر اصلی همون نتیجه result مقدار اولیش 0 باشه و وقتی چک میکنی خطور رو اگه مقدار بیشتر از 0 بود یعنی اون مقادیر جمع زده شدن
ببینید یه سمپل نوشتم
مجموع جمع 2 تکست باکس--(اینجا من کمبو نذاشتم)--رو توی تکست3 ریختم بعد خط های داخل فایل رو بررسی میکنیم اگه بود داخل لیست باکس میریزه
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
if (!File.Exists("test.txt"))
{
File.Create("test.txt");
}
}
private void button1_Click(object sender, EventArgs e)
{
int counter = 0;
int txt1 = int.Parse(textBox1.Text);
int txt2 = int.Parse(textBox1.Text);
counter = txt1 + txt2;
textBox3.Text = counter.ToString();
string line;
System.IO.StreamReader file = new System.IO.StreamReader("test.txt");
while ((line = file.ReadLine()) != null)
{
if (line.Contains(counter.ToString()))
{
listBox1.Items.Add(counter.ToString() + ": " + line);
}
counter++;
}
file.Close();
}
}
}