错误“异常是命名空间,但用作类型” [英] Error "Exception is the namespace but used as a type"

查看:59
本文介绍了错误“异常是命名空间,但用作类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到Exception是命名空间但用作类型错误



I am getting "Exception is the namespace but used as a type" Error

public static void logger(Exception exception)
{
StringBuilder sbExceptionMessage = new StringBuilder();
}



如何解决这个问题?



这是.cs文件。




How to resolve this?

this is the .cs file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
using System.Text;

namespace Exception
{
    public class Class1
    {
        public static void logger(Exception ex) //getting error here
        {


        }
    }
}

推荐答案

您已声明 Exception 成为项目中的命名空间。

现在当您尝试在您的项目中使用它时异常处理程序即(Exception ex),您将遇到问题。这被假定为编译器的命名空间。



试试这个 -

You have declared Exception to be a namespace in your project.
Now when you try and use it in your exception handler i.e. (Exception ex), you will run into a problem. This is assumed to be a namespace by the compiler.

Try this instead -
namespace Exception
{
    public class Class1
    {
        public static void logger(System.Exception ex) //getting error here
        {


        }
    }
}


这篇关于错误“异常是命名空间,但用作类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆