【发布时间】:2021-11-02 01:40:05
【问题描述】:
我尝试使用类似 using Printer; 但它不起作用。
我只想使用 P(); 而不是 Printer.P();
文件打印机.cs
using System;
namespace animals
{
public class Printer
{
public static void P()
{
P("\a");
}
public static void P(object val, bool doEnterAfterLine = true, bool printInOneLine = false)
{
P(val.ToString());
if (doEnterAfterLine)
Console.WriteLine(); //enter
}
static void P(bool printSeparator = false)
{
if (printSeparator == false)
return;
P("---------------------------------------------------------", true);
}
static void P(string value = "none", bool modifyColor = false, bool ding = false, bool printInOneLine = false)
{
var oldColor = Console.ForegroundColor;
if (modifyColor)
Console.ForegroundColor = ConsoleColor.Magenta;
if (printInOneLine)
Console.Write(value + " ");
else
Console.WriteLine(value);
Console.ForegroundColor = oldColor; //recover color
if (ding)
{
Console.Write("\a");
}
}
}
}
文件 Program.cs
using System;
// this resolve problem: using static animals.Printer;
namespace animals
{
class Program
{
static void Main(string[] args)
{
Printer.P(); // it works
P(); // info: does not exist in current context
}
}
}
【问题讨论】:
-
你的意思是
using static animals.Printer.P;? -
@Omar 不是
using static animals.Printer;? -
可能,我不记得了。 using - static modifier
-
除非您没有显示所有代码...
Printer类无效...P(“/a”)...? -
你应该有更大的事情需要担心,但是如果你查看使用文档,你会发现你需要什么
标签: c#