繁体   English   中英

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

[英]Call static method in another class library

如何在另一个类库中调用静态方法? 因为我创建了2个类库Common和另一个调用DAL,并且已经在我的DAL类库中添加了Commmon dll引用,所以之后我找不到我的方法名。 没有其他方法可以解决吗?

类库:通用

using System;

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

类库: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.;
    }
}

您不能从类中该方法之外的位置调用Log.Error()方法。

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