C#中提示错误 当前上下文中不存在名称“Mathod”

usingSystem;namespaceproMethod{classMathod{publiclongFactorial(longn){returnn<=0?1:n*... using System;
namespace proMethod
{
class Mathod
{
public long Factorial(long n)
{
return n <= 0 ? 1 : n * Factorial(n - 1);
}
public static long SFactorial(long n)
{
return n <= 0 ? 1 : n * SFactorial(n - 1);
}
}
}
class Class
{
static void Main(string[] args)
{
Console.WriteLine("使用静态方法\n求整数6的阶乘,结果为{0}", Mathod.SFactorial(6));
Mathod m = new Mathod();
Console.WriteLine("使用实例方法\n求整数6的阶乘,结果为{0}", m.Factorial(6));
Console.ReadLine();
}
}
错误 1 当前上下文中不存在名称“Mathod”
错误 2 找不到类型或命名空间名称“Mathod”(是否缺少 using 指令或程序集引用?)
错误 3 找不到类型或命名空间名称“Mathod”(是否缺少 using 指令或程序集引用?)
展开
 我来答
simonzhl
推荐于2017-11-23 · TA获得超过289个赞
知道小有建树答主
回答量:120
采纳率:0%
帮助的人:171万
展开全部
你的括号包错了.

把class Class放在namespace proMethod 命名空间中。
调整一下打括号就可以了。

详细如下:

using System;
namespace proMethod
{
class Mathod
{
public long Factorial(long n)
{
return n <= 0 ? 1 : n * Factorial(n - 1);
}
public static long SFactorial(long n)
{
return n <= 0 ? 1 : n * SFactorial(n - 1);
}
}

class Class
{
static void Main(string[] args)
{
Console.WriteLine("使用静态方法\n求整数6的阶乘,结果为{0}", Mathod.SFactorial(6));
Mathod m = new Mathod();
Console.WriteLine("使用实例方法\n求整数6的阶乘,结果为{0}", m.Factorial(6));
Console.ReadLine();
}
}
}

[广告]
欢迎IT人士加入★IT从业者俱乐部★
Q群:5874081
面向IT从业者的信息交流空间。
TableDI
2024-07-18 广告
`VLOOKUP` 匹配出错误的数据通常是由于以下几个原因:1. **查找值错误**:输入的查找值与数据源中的值不匹配,可能是因为拼写错误、大小写不一致或存在不可见的字符。2. **查找区域设置错误**:查找区域的首列必须包含要查找的值,且... 点击进入详情页
本回答由TableDI提供
金风泊岸
2010-11-13 · TA获得超过217个赞
知道小有建树答主
回答量:250
采纳率:0%
帮助的人:162万
展开全部
using System;
namespace proMethod
{
public static class Mathod
{
public long Factorial(long n)
{
return n <= 0 ? 1 : n * Factorial(n - 1);
}
public static long SFactorial(long n)
{
return n <= 0 ? 1 : n * SFactorial(n - 1);
}
}
}
class Class
{
static void Main(string[] args)
{
Console.WriteLine("使用静态方法\n求整数6的阶乘,结果为{0}", Mathod.SFactorial(6));
Mathod m = new Mathod();
Console.WriteLine("使用实例方法\n求整数6的阶乘,结果为{0}", m.Factorial(6));
Console.ReadLine();
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
十米若狂忆15
2010-11-13 · TA获得超过138个赞
知道答主
回答量:190
采纳率:100%
帮助的人:76.1万
展开全部
【请修改成】
using System;
namespace proMethod
{
class Mathod
{
public long Factorial(long n)
{
return n <= 0 ? 1 : n * Factorial(n - 1);
}
public static long SFactorial(long n)
{
return n <= 0 ? 1 : n * SFactorial(n - 1);
}
}
class Class
{
static void Main(string[] args)
{
Console.WriteLine("使用静态方法\n求整数6的阶乘,结果为{0}", Mathod.SFactorial(6));
Mathod m = new Mathod();
Console.WriteLine("使用实例方法\n求整数6的阶乘,结果为{0}", m.Factorial(6));
Console.ReadLine();
}

}
【或者改成】
using System;
namespace proMethod
{
class Mathod
{
public long Factorial(long n)
{
return n <= 0 ? 1 : n * Factorial(n - 1);
}
public static long SFactorial(long n)
{
return n <= 0 ? 1 : n * SFactorial(n - 1);
}
}
}
using proMethod;
namespace a
{
class Class
{
static void Main(string[] args)
{
Console.WriteLine("使用静态方法\n求整数6的阶乘,结果为{0}", Mathod.SFactorial(6));
Mathod m = new Mathod();
Console.WriteLine("使用实例方法\n求整数6的阶乘,结果为{0}", m.Factorial(6));
Console.ReadLine();
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式