如何使用 C# 将整个文件读取为字符串? [英] How to read an entire file to a string using C#?
本文介绍了如何使用 C# 将整个文件读取为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将文本文件读入字符串变量的最快方法是什么?
What is the quickest way to read a text file into a string variable?
我知道它可以通过多种方式完成,例如读取单个字节,然后将它们转换为字符串.我正在寻找一种代码最少的方法.
I understand it can be done in several ways, such as read individual bytes and then convert those to string. I was looking for a method with minimal coding.
推荐答案
string contents = File.ReadAllText(@"C: emp est.txt");
这篇关于如何使用 C# 将整个文件读取为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文