扩展方法对于Console类 [英] extension method For Console Class
本文介绍了扩展方法对于Console类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为名为WriteLog的控制台类添加扩展方法。我试过这个
i want to add an extension method for console class named "WriteLog". i tried like this
using System;
namespace MyName
{
static class MyName
{
public static void WriteLog(this Console c)
{
Console.WriteLine("Hello");
}
}
}
现在我在命名空间中使用它,但它没有显示在控制台班......
请告诉我哪里错了.........
now i am using this by namespace but its not showing in console class...
pls tell me where i am wrong.........
推荐答案
控制台是一个静态类。您不能将扩展方法添加到静态类。
Console is a static class. You can not add extension method to a static class.
这篇关于扩展方法对于Console类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文