C# |检查控制台上的输出是否重定向
给定 C# 中的正常控制台,任务是检查输出是否在控制台上被重定向。
方法:这可以使用 C# 中系统包的控制台类中的等输出定向属性来完成。此属性返回一个布尔值,说明输出是否被重定向。
程序:
// C# program to demonstrate the
// Console.IsOutputRedirected Property
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GFG {
class Program {
// Main Method
static void Main(string[] args)
{
// Check if Output is Redirected
Console.WriteLine("Is Output Redirected: {0}",
Console.IsOutputRedirected);
}
}
}
输出:
版权属于:月萌API www.moonapi.com,转载请注明出处