关于文件存储 [英] regarding the file storage

查看:48
本文介绍了关于文件存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何使用c#将二维数组存储在文本文件中吗?


谢谢,

解决方案

为什么?只需使用Data Contract,所有内容将自动为您存储和加载,而无需您花费很多精力.作为奖励,您将看到经过训练的易于阅读的XML或JSON存储的外观.

请参阅:
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

另请参阅我过去关于以下主题的答案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [反序列化json字符串数组 [

a[0][0] = 5
a[0][1] = 7
..
a[1][0] = 27
a[1][1] = -7
..



(请参阅
如何:写入文本文件 [序列化 [ ^ ]. blockquote>

can any one please tell me how to store 2-D array in a text file using c#


thanks,

解决方案

Why? Just use Data Contract and all will be stored and loaded for you automatically and without much of your effort. As a bonus, you will see how a cultured and well-readable XML or JSON storage looks like.

Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past answers on the topic:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

—SA


Store each row of the array on a separate line. All columns of a row will thus have to placed on one line. Separate each of the column values with a suitable separator, i.e. a character or a string that cannot be part of any given value. If your array only contains numbers the choice of the column separator is easier to solve, just take a space or a tab character. Still begs the question what you are trying to achieve by that, but that can only answered by yourself. :)

Regards,

Manfred


If you want to store the values in a human-friendly format (since you are using text file, I assume that) the you may write ''verbosely'' each item, e.g.

a[0][0] = 5
a[0][1] = 7
..
a[1][0] = 27
a[1][1] = -7
..



(see How to: Write to a Text File[^]).

On the other hand, if you need to store the array for later retrieval in you program then you may prefer serialization[^].


这篇关于关于文件存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆