我是C#中的一个完全noob和一个初学者程序员,但我正在阅读Roslyn和'C#7.0中有什么新东西',我发现了一些非常有趣的东西,我找不到我需要的答案。
在此link中,所有给出的示例都包含WriteLine("something");
而不是Console.WriteLine("something");
,例如:
public void PrintCoordinates(Point p)
{
p.GetCoordinates(out int x, out int y);
WriteLine($"({x}, {y})");
}
我的问题是:我该怎么做?
这样的事情会起作用吗?
public static void WriteLine(string v) => Console.WriteLine(v);
答案 0 :(得分:17)
尝试using static
:
using static System.Console;
...
WriteLine("some text");
答案 1 :(得分:6)
从C#6.0开始,这是可能的:
Using the "Views Data Export" module
------------------------------------
1. Add a new "Data export" display to your view.
2. Change its "Style" to the desired export type. e.g. "CSV file".
3. Configure the options (such as name, quote, etc.). You can go back and do
this at any time by clicking the gear icon next to the style plugin you just
selected.
4. Give it a path in the Feed settings such as "path/to/view/csv".
5. Optionally, you can choose to attach this to another of your displays by
updating the "Attach to:" option in feed settings.
但是,以前版本的C#没有静态导入。
答案 2 :(得分:4)
您可以使用Action
:
Action<string> WriteLine = (text) => Console.WriteLine(text);