【发布时间】:2021-03-15 13:09:15
【问题描述】:
你好请问我该如何解决这个错误(mcs -out:main.exe main.cs
main.cs(8,6): error CS1525: Unexpected symbol namespace', expecting identifier' or `static'
编译失败:1 个错误,0 个警告
)从这个练习(使用+操作将两次相加编写一个程序来测试一个类)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using namespace v3
{
public class Time
{
private int hr, mn, sc;
public Time()
{
hr = 0;
mn = 0;
sc = 0;
}
public Time(int h, int m, int s)
{
hr = h;
mn = m;
sc = s;
}
public void display()
{
Console.WriteLine(hr);
Console.WriteLine(":");
Console.WriteLine(mn);
Console.WriteLine(":");
Console.WriteLine(sc);
Console.WriteLine("\n");
}
public static class MembresGlobals
{
static int Main()
{
Time time_1 = new Time(3, 5, 2);
Time time_2 = new Time(2, 5, 3);
Time time_sum = new Time();
time_sum.CopyFrom(time_1 + time_2);
time_1.display();
time_2.display();
time_sum.display();
}
}
public static Time operator + (Time ImpliedObject, Time t2)
{
int totalsecs = (ImpliedObject.hr * 3600) + (ImpliedObject.mn * 60) + ImpliedObject.sc + (t2.hr * 3600) + (t2.mn * 60) + t2.sc;
int h = totalsecs / (60 * 60);
int m = totalsecs % (60 * 60) / 60;
int s = totalsecs % (60 * 60) % 60;
return new Time(h, m, s);
}
}
}
【问题讨论】:
-
“你不必在命名空间之前使用 using” - 来自 Saravanan 的回答
标签: c# .net visual-studio c#-3.0 repl.it