【问题标题】:How to use method from one file on other file [duplicate]如何在另一个文件上使用一个文件中的方法[重复]
【发布时间】:2019-12-30 12:19:21
【问题描述】:

我想在另一个文件(类)中使用一个方法。可以看到

// first class file
namespace AutomatskI
{
    class Method{
         public void client()
         {
           // some code
         }
// second class file
namespace AutomatskaIA
{
    class AutomaticTestRun
        public void login()
           {
             // Here i want to use that code
              client();
           }

【问题讨论】:

    标签: c#


    【解决方案1】:

    您应该在第二个库中引用您的第一个库

    // Reference your first library like this
    using AutomatskI;
    
    namespace AutomatskaIA
    {
        class AutomaticTestRun
        {
            public void login()
            {
                // Then reach this class method like this
                Method method = new Method();
                method.client();
                // Or use a static class instead by putting a 'static' tag in class name. 
                // So you don't have to create an instance of this class in order
                // to use its methods. Then you can do it like this:
                // Method.client();
            }
     // ...
    

    请在发布之前格式化您的代码,以便人们更容易阅读您的代码。

    【讨论】:

    • 谢谢,格式错误,下次会尽量小心。
    猜你喜欢
    • 1970-01-01
    • 2013-07-19
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 2020-02-12
    • 2012-10-29
    相关资源
    最近更新 更多