【问题标题】:is there python's as keyword in C#C# 中是否有 python 的 as 关键字
【发布时间】:2020-09-17 07:35:09
【问题描述】:

当我使用 python
我可以使用 as 关键字替换库名称

这是一个示例代码:

import matplotlib.pyplot as plt

plt.rc('font', family = 'Malgun Gothic')
plt.title("title")
plt.plot(a, label = 'maximum degree', color = 'cyan', linestyle=':', marker = 'v')
plt.legend()
plt.show()

根据这段代码 matplotlib.pyplot 被 'as' 关键字替换为 plt

我想在 C# 中使用这个关键字 as

  • C#中是否有python的as关键字

【问题讨论】:

  • 你可以这样做:using O = Newtonsoft.Json.Linq.JObject;
  • 你展示了python,但没有展示C#。这个问题有点落后
  • @MichaelRandall 对我来说似乎很好; “这是我可以在 Python 中做的一件事(具体示例);我可以在 C# 中做到这一点吗?” - 没有什么倒退的
  • @MarcGravell 绝对不会争论,但没有参考。我的意思是,在 C# 中,操作员试图 as 他们有什么问题。

标签: python c# keyword


【解决方案1】:

在c#中,“使用别名”;如果 matplotlib.pyplot 是完全限定的 .NET 类型:

using plt = matplotlib.pyplot;

【讨论】:

    【解决方案2】:

    您可以像这样为您的 using 命名空间/类设置别名:

    using NsJson = Newtonsoft.Json;
    
    
    public void MyMethod(){
    
        new NsJson.Linq.JObject(); //example
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 2011-03-10
      • 2019-11-09
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      相关资源
      最近更新 更多