c# 中的 stdout 与 console.write [英] stdout vs console.write in c#
问题描述
我对 C#/编程非常陌生,作为学习练习,我完成了将文本更改为小写的在线挑战.挑战指定它必须打印到标准输出",但我使用 Console.Writeline
I am VERY new to C#/programming and as a learning exercise completed an online challenge to change text to lowercase. The challenge specified it must 'print to stdout' yet I completed the challenge by using Console.Writeline
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lowercase
{
class Program
{
static void Main(string[] args)
{
using ( StreamReader reader = new StreamReader("TextFile1.txt"))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
Console.WriteLine(line.ToLower());
}
Console.ReadLine();
}
}
}
}
stdout
只是输出到控制台的另一个名称(提交可以是多种不同的语言),或者在线代码提交只是没有正确检查输出.我在谷歌上搜索了stdout c#",但没有完全理解结果.
Is stdout
just another name for outputting to console (submissions could be in many different languages) or did the online code submission just not check the output properly. I have googled 'stdout c#' but don't fully understand the results.
推荐答案
在像 C 和 C++ 这样的语言中,有一个名为 stdout
的全局变量,它是一个指向标准输出流的指针.因此,即使在 C 语言的上下文之外,stdout
已成为标准输出流"的常用缩写.
In languages like C and C++, there is a global variable with the name stdout
, which is a pointer to the standard output stream. Thus, stdout
has become a commonly used abbreviation for "standard output stream" even outside the context of the C language.
现在,C# 做了什么?我们来看看Console.WriteLine的文档(强调我的):
Now, what does C# do? Let's have a look at the documentation of Console.WriteLine (emphasis mine):
写入指定的字符串值,后跟当前行终止符,到标准输出流.
Writes the specified string value, followed by the current line terminator, to the standard output stream.
所以,是的,Console.WriteLine
正是您需要做的.如果您需要对标准输出流的直接引用(提示:您通常不需要),您可以使用 Console.Out 属性.
So, yes, Console.WriteLine
does exactly what you need to do. If you need a direct reference to the standard output stream (Hint: you usually don't), you can use the Console.Out property.
这篇关于c# 中的 stdout 与 console.write的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!