Console.Out 属性

默认情况下,此属性设置为标准输出流。 此属性可以设置为另一个流SetOut方法。

请注意,调用Console.Out.WriteLine方法是等效于调用相应WriteLine方法。

下面的示例使用Out属性显示包含到标准输出设备的应用程序的当前目录中的文件的名称的数组。 然后将标准输出设置为一个名为 Files.txt 文件,并列出了对文件的数组元素。 最后,它将输出设置写入标准输出流,也不会显示数组元素到标准输出设备。

using System;
using System.IO; public class Example
{
public static void Main()
{
// Get all files in the current directory.
string[] files = Directory.GetFiles(".");
Array.Sort(files); // Display the files to the current output source to the console.
Console.WriteLine("First display of filenames to the console:");
Array.ForEach(files, s => Console.Out.WriteLine(s));
Console.Out.WriteLine(); // Redirect output to a file named Files.txt and write file list.
StreamWriter sw = new StreamWriter(@".\Files.txt");
sw.AutoFlush = true;
Console.SetOut(sw);
Console.Out.WriteLine("Display filenames to a file:");
Array.ForEach(files, s => Console.Out.WriteLine(s));
Console.Out.WriteLine(); // Close previous output stream and redirect output to standard output.
Console.Out.Close();
sw = new StreamWriter(Console.OpenStandardOutput());
sw.AutoFlush = true;
Console.SetOut(sw); // Display the files to the current output source to the console.
Console.Out.WriteLine("Second display of filenames to the console:");
Array.ForEach(files, s => Console.Out.WriteLine(s)); Console.ReadKey();
}
}

XmlDocument.Save 方法 (String)

只有当 PreserveWhitespace 设置为 true 时,才在输出文件中保留空白。

当前 XmlDocument 对象的 XmlDeclaration 确定保存的文档的编码属性。编码属性值取自 XmlDeclaration.Encoding 属性。如果 XmlDocument 不具有 XmlDeclaration,或者如果 XmlDeclaration 没有编码属性,则保存的文档也不会有这些属性。

保存文档时,生成 xmlns 属性以正确保持节点标识(本地名称 + 命名空间 URI)。例如,下面的 C# 代码

XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateElement("item","urn:1"));
doc.Save(Console.Out);

生成此 xmls 属性 <item xmls="urn:1"/>

该方法是文档对象模型 (DOM) 的 Microsoft 扩展。

using System;
using System.Xml; public class Sample { public static void Main() { // Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>"); // Add a price element.
XmlElement newElem = doc.CreateElement("price");
newElem.InnerText = "10.95";
doc.DocumentElement.AppendChild(newElem); // Save the document to a file. White space is
// preserved (no white space).
doc.PreserveWhitespace = true;
doc.Save("data.xml"); }
}

Console.Out 属性和 XmlDocument.Save 方法 (String)的更多相关文章

  1. spring cloud spring boot JPA 克隆对象修改属性后 无法正常的执行save方法进行保存或者更新

    2019-12-1220:34:58 spring cloud spring boot JPA 克隆对象修改属性后 无法正常的执行save方法进行保存或者更新 未解决

  2. jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解

    jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解 jQuery中操纵元素属性的方法: attr(): 读或者写匹配元素的属性值. removeAttr(): 从匹配的 ...

  3. 扩展JPA方法,重写save方法

    为什么要重构save? jpa提供的save方法会将原有数据置为null,而大多数情况下我们只希望跟新自己传入的参数,所以便有了重写或者新增一个save方法. 本着解决这个问题,网上搜了很多解决方案, ...

  4. 华为交换机Console口属性配置

    华为交换机Console口属性配置 一.设置通过账号和密码(AAA验证)登陆Console口 进入 Console 用户界面视图 <Huawei>system-view [Huawei]u ...

  5. 转载:java 中对类中的属性使用set/get方法的意义和用法

    经常看到有朋友提到类似:对类中的属性使用set/get方法的作用?理论的回答当然是封闭性之类的,但是这样对我们有什么作用呢?为什么要这样设计?我直接使用属性名来访问不是更直接,代码更简洁明了吗?下面我 ...

  6. C# String.split()用法小结。String.Split 方法 (String[], StringSplitOptions)

    split()首先是一个分隔符,它会把字符串按照split(' 字符')里的字符把字符串分割成数组,然后存给一个数组对象. 输出数组对象经常使用foreach或者for循环. 第一种方法 string ...

  7. JavaScript Number 对象 Javascript Array对象 Location 对象方法 String对象方法

    JavaScript Number 对象 Number 对象属性 属性 描述 constructor 返回对创建此对象的 Number 函数的引用. MAX_VALUE 可表示的最大的数. MIN_V ...

  8. [原创]java WEB学习笔记79:Hibernate学习之路--- 四种对象的状态,session核心方法:save()方法,persist()方法,get() 和 load() 方法,update()方法,saveOrUpdate() 方法,merge() 方法,delete() 方法,evict(),hibernate 调用存储过程,hibernate 与 触发器协同工作

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  9. 01-03-02-2【Nhibernate (版本3.3.1.4000) 出入江湖】CRUP操作-Save方法的一些问题

    此文由于当时不知道NHibernate的Sava方法不是更新操作,不知道Save就是Add,造成如下荒唐的求证过程,但结论是对的 ,可报废此文,特此声明. NHibernate--Save方法: Cu ...

随机推荐

  1. ubuntu 16.04 安装后需要做的事情

    1. 更改软件源 sudo gedit /etc/apt/source.list 在底部加入:(如果可以,把Ubuntu官方源注释掉“#_____”) # deb cdrom:[Ubuntu 16.0 ...

  2. java多线程sleep,wait,yield方法区别

    sleep() 方法sleep()的作用是在指定的毫秒数内让当前“正在执行的线程”休眠(暂停执行).这个“正在执行的线程”是指this.currentThread()返回的线程.sleep方法有两个重 ...

  3. MySQL数据库3分组与单表、多表查询

    目录 一.表操作的补充 1.1null 和 not null 1.2使用not null的时候 二.单表的操作(import) 2.1分组 2.1.1聚合函数 2.1.2group by 2.1.3h ...

  4. 【leetcode】1103. Distribute Candies to People

    题目如下: We distribute some number of candies, to a row of n = num_people people in the following way: ...

  5. 【leetcode】837. New 21 Game

    题目如下: 解题思路:这个题目有点像爬楼梯问题,只不过楼梯问题要求的计算多少种爬的方式,但是本题是计算概率.因为点数超过或者等于K后就不允许再增加新的点数了,因此我们可以确定最终Alice拥有的点数的 ...

  6. Git整理[1] git cherry-pick的使用

    简单地说 git cherry-pick为”挑拣”提交 ,挑取某次提交合并到其他分支上,而不用合并整个分支. 参数: git cherry-pick [<options>] <com ...

  7. springboot2.0+mysql整合mybatis,发现查询出来的时间比数据库datetime值快了8小时

    参考:https://blog.csdn.net/lx12345_/article/details/82020858 修改后查询数据正常

  8. cookie、session和会话保持

    1.会话 在程序中,会话跟踪是很重要的事情.理论上,一个已登录用户,在这次登录后进行的所有请求操作都应该属于同一个会话,而另一个用户的所有请求操作则应该属于另一个会话,二者不能混淆.例如,用户 A 在 ...

  9. js基础补漏

    1.for...in 和 for...of有何区别 for ... in循环由于历史遗留问题,它遍历的实际上是对象的属性名称.一个Array数组实际上也是一个对象,它的每个元素的索引被视为一个属性. ...

  10. docker-dnsmasq使用

    docker-dnsmasq支持通过web页面配置域名映射,镜像地址:https://hub.docker.com/r/jpillora/dnsmasq 使用步骤如下: 1.在Docker宿主上创建 ...