用C# 将坐标轴数组写入文件,并读出文件坐标数组,赋值给数组
写入文件格式可见是如:-10,2-9,24-8,45……读出来的时候可以将他们X坐标赋值给a[]Y坐标给b[]或者用Point定义都可以~求指导~~...
写入文件 格式可见 是 如: -10,2 -9,24 -8,45 ……读出来的时候可以 将他们 X坐标赋值给 a[] Y坐标给b[] 或者 用 Point 定义 都可以~ 求指导~~
展开
1个回答
展开全部
public void Save()
{
Point[] pt = {new Point(-10,2), new Point(-9,24), new Point(-8,45)};
string filePath = @"D:\Point.txt";
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath))
{
for (int i = 0; i < pt.Length; i++)
{
sw.Write(pt[i].X);
sw.Write(",");
sw.Write(pt[i].Y);
sw.Write(" ");
}
}
}
public void Load()
{
string filePath = @"D:\Point.txt";
using (System.IO.StreamReader sr = new System.IO.StreamReader(filePath))
{
string str = sr.ReadToEnd();
string[] ss = str.Split(new char[] { ' ', ',' });
int ptCount = ss.Length / 2;
Point[] pt = new Point[ptCount];
for (int i = 0; i < ptCount; i++)
{
pt[i].X = System.Convert.ToInt32(ss[2*i]);
pt[i].Y = System.Convert.ToInt32(ss[2 * i + 1]);
}
}
}
{
Point[] pt = {new Point(-10,2), new Point(-9,24), new Point(-8,45)};
string filePath = @"D:\Point.txt";
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath))
{
for (int i = 0; i < pt.Length; i++)
{
sw.Write(pt[i].X);
sw.Write(",");
sw.Write(pt[i].Y);
sw.Write(" ");
}
}
}
public void Load()
{
string filePath = @"D:\Point.txt";
using (System.IO.StreamReader sr = new System.IO.StreamReader(filePath))
{
string str = sr.ReadToEnd();
string[] ss = str.Split(new char[] { ' ', ',' });
int ptCount = ss.Length / 2;
Point[] pt = new Point[ptCount];
for (int i = 0; i < ptCount; i++)
{
pt[i].X = System.Convert.ToInt32(ss[2*i]);
pt[i].Y = System.Convert.ToInt32(ss[2 * i + 1]);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询