首个程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security.Cryptography.X509Certificates;
namespace Test1
{
class Program
{
{
class Program
{
class Txthander// 操作TXT文件类
{
{
//public string txtFullName;
//public string TxtFullNamE
//{
// set
// {
// txtFullName = value;
// }
// get
// { return txtFullName; }
//public string TxtFullNamE
//{
// set
// {
// txtFullName = value;
// }
// get
// { return txtFullName; }
//}
//readonly string filename = Convert.ToString(Console.ReadLine()); //获取完整路径
public string filename = @"J:\a.txt";
public void GetAlltext()//方法:读取文件中的所有内容
{
string str1 = File.ReadAllText(filename);
Console.WriteLine(str1);
}
public void GetFirstLine()//读取文件中的第一行
{
string[] strs1 = File.ReadAllLines(filename);
int a = strs1.Length;
Console.WriteLine("首行:" + strs1[0]);
char[] seperator = { ' ' };
string[] valuegroup = strs1[0].Split(seperator);
}
public void GetFinalLine()//读取最后一行字符
{
string[] strs1 = File.ReadAllLines(filename);
int a = strs1.Length;
Console.WriteLine("末行:"+ strs1[a-1]);
}
public void Streamread1() //全读出???
{
StreamReader sR1 = File.OpenText(filename);
public void GetFinalLine()//读取最后一行字符
{
string[] strs1 = File.ReadAllLines(filename);
int a = strs1.Length;
Console.WriteLine("末行:"+ strs1[a-1]);
}
public void Streamread1() //全读出???
{
StreamReader sR1 = File.OpenText(filename);
string nextline;
while((nextline=sR1.ReadLine())!=null)
{
Console.WriteLine(nextline);
}
sR1.Close();
}
{
Console.WriteLine(nextline);
}
sR1.Close();
}
public void Streamread() //全读出????
{
StreamReader sR = File.OpenText(filename);
string nextLine;
while ((nextLine = sR.ReadLine()) != null)
{
Console.WriteLine(nextLine);
}
sR.Close();
}
public void WriteStringOverride() //内容写入文件且完全覆盖原TXT内的内容
{
Console.WriteLine("please input string what you want to write");
string str = Console.ReadLine();
File.WriteAllText( filename, str);
}
public void WriteAfterFinalLine()//最后一行写入内容,不覆盖原来的内容
{
StreamWriter sw = new StreamWriter(filename, true);
Console.WriteLine("Please input what your want to input in the final line");
sw.WriteLine(Console.ReadLine());
sw.Close();
}
public void TransferToNumber()//将最后一行的内容转化成独立的数字数组
{
string[] strs1 = File.ReadAllLines(filename);
int a = strs1.Length;
Console.WriteLine("最后一行是:" + strs1[a - 1]);
char[] seperator = { ' ' };
string[] valuegroup = strs1[a - 1].Split(seperator);
{
StreamReader sR = File.OpenText(filename);
string nextLine;
while ((nextLine = sR.ReadLine()) != null)
{
Console.WriteLine(nextLine);
}
sR.Close();
}
public void WriteStringOverride() //内容写入文件且完全覆盖原TXT内的内容
{
Console.WriteLine("please input string what you want to write");
string str = Console.ReadLine();
File.WriteAllText( filename, str);
}
public void WriteAfterFinalLine()//最后一行写入内容,不覆盖原来的内容
{
StreamWriter sw = new StreamWriter(filename, true);
Console.WriteLine("Please input what your want to input in the final line");
sw.WriteLine(Console.ReadLine());
sw.Close();
}
public void TransferToNumber()//将最后一行的内容转化成独立的数字数组
{
string[] strs1 = File.ReadAllLines(filename);
int a = strs1.Length;
Console.WriteLine("最后一行是:" + strs1[a - 1]);
char[] seperator = { ' ' };
string[] valuegroup = strs1[a - 1].Split(seperator);
}
}
enum Bank
{
Alipay,
AlipayFix,
SuzhouBank,
PuFaBank,
ZhaoShangBank,
GuPiao,
ToWangRule,
Others,
House,
Outer
}//
class ZhangDan:Txthander
{
}
enum Bank
{
Alipay,
AlipayFix,
SuzhouBank,
PuFaBank,
ZhaoShangBank,
GuPiao,
ToWangRule,
Others,
House,
Outer
}//
class ZhangDan:Txthander
{
public void CheckMoney()//进行不同账户中的金额转移
{
string[] strs1 = File.ReadAllLines(filename);
int a = strs1.Length;
char[] seperator = { ' ' };
string[] valuegroup = strs1[a - 1].Split(seperator);//获取最后一行的数组
Console.WriteLine("Select the Source");
int sourceIndex = Convert.ToInt32(Console.ReadLine()) - 1;//源的序列号
double sourcePosition = Convert.ToDouble(valuegroup[sourceIndex]); //取出位置的初始值
{
string[] strs1 = File.ReadAllLines(filename);
int a = strs1.Length;
char[] seperator = { ' ' };
string[] valuegroup = strs1[a - 1].Split(seperator);//获取最后一行的数组
Console.WriteLine("Select the Source");
int sourceIndex = Convert.ToInt32(Console.ReadLine()) - 1;//源的序列号
double sourcePosition = Convert.ToDouble(valuegroup[sourceIndex]); //取出位置的初始值
Console.WriteLine("Select the target");
int targetIndex = Convert.ToInt32(Console.ReadLine()) - 1;//目标的序列号
double targetPosition = Convert.ToDouble(valuegroup[targetIndex]);//放入位置的值初始值
Console.WriteLine("Input the number that you want transfer");
double numberTotransfer = Convert.ToDouble(Console.ReadLine());//想要处理的值
sourcePosition -= numberTotransfer;
targetPosition += numberTotransfer;
int targetIndex = Convert.ToInt32(Console.ReadLine()) - 1;//目标的序列号
double targetPosition = Convert.ToDouble(valuegroup[targetIndex]);//放入位置的值初始值
Console.WriteLine("Input the number that you want transfer");
double numberTotransfer = Convert.ToDouble(Console.ReadLine());//想要处理的值
sourcePosition -= numberTotransfer;
targetPosition += numberTotransfer;
valuegroup[sourceIndex] = Convert.ToString(sourcePosition);// 将更新后值赋给源位置
valuegroup[targetIndex] = Convert.ToString(targetPosition);//将更新后的值赋给目标位置
string newValueGroup;
valuegroup[targetIndex] = Convert.ToString(targetPosition);//将更新后的值赋给目标位置
string newValueGroup;
//以下为计算total的值
double totalValue = 0;
for (int i = 0; i < valuegroup.Length-1; i++)
{
totalValue+= Convert.ToDouble(valuegroup[i]);
}
//Console.WriteLine("total"+valuegroup[valuegroup.Length-1]);
valuegroup[valuegroup.Length - 1] = Convert.ToString(totalValue);
double totalValue = 0;
for (int i = 0; i < valuegroup.Length-1; i++)
{
totalValue+= Convert.ToDouble(valuegroup[i]);
}
//Console.WriteLine("total"+valuegroup[valuegroup.Length-1]);
valuegroup[valuegroup.Length - 1] = Convert.ToString(totalValue);
newValueGroup = string.Join(" ", valuegroup);
StreamWriter sw = new StreamWriter(filename, true);//将
Console.WriteLine("Please input what your want to input in the final line");
sw.WriteLine(newValueGroup);
sw.Close();
StreamWriter sw = new StreamWriter(filename, true);//将
Console.WriteLine("Please input what your want to input in the final line");
sw.WriteLine(newValueGroup);
sw.Close();
}
}
static void Main(string[] args)
{
static void Main(string[] args)
{
var ta = new ZhangDan();
ta.GetFirstLine();
ta.GetFinalLine();
ta.CheckMoney();
Console.WriteLine("now your money is:");
ta.GetFirstLine();
ta.GetFinalLine();
ta.GetFirstLine();
ta.GetFinalLine();
Console.ReadKey();
}
}
}
}
}
}