简体   繁体   English

在另一个类库中调用静态方法

[英]Call static method in another class library

How to call static method in another class library? 如何在另一个类库中调用静态方法? Because I created 2 class library Common and another call DAL, and I already add Commmon dll reference in my DAL class library, after that I cannot find out my method name. 因为我创建了2个类库Common和另一个调用DAL,并且已经在我的DAL类库中添加了Commmon dll引用,所以之后我找不到我的方法名。 Isn't got other method to solve it? 没有其他方法可以解决吗?

Class library : Common 类库:通用

using System;

    namespace Common
    {
        public class Log
        {
            public static bool Error(Exception ex)
            {
                return true;
            }
        }
    }

Class library : DAL 类库:DAL

using Common
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class MenuD
    {
        Log.;
    }
}

You can't call the Log.Error() method from that location in the class, outside of a method. 您不能从类中该方法之外的位置调用Log.Error()方法。

Call it from within a method in the MenuD class. MenuD类的方法中调用它。

public class MenuD
{
    public void SomeMethod()
    {
        try
        {
            // do something that could throw an exception
        }
        catch (Exception ex)
        {
            var isLogged = Log.Error(ex);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM