【发布时间】:2015-12-16 22:02:59
【问题描述】:
我想从 Program.cs 中的 main 调用 Alpha 类中的 Apple 方法和 Beta 类中的 Beet 方法。
我无法理解我在下面的代码中做错了什么。
非常感谢您查看此问题!
我有一个新项目,只有三个非常简单的文件:
- Program.cs
- Alpha.cs
- Beta.cs
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class Program
{
static void Main(string[] args)
{
// Note: there are red squiggly lines under Apple and Beet
// in Visual Studio.
Apple a = new Apple();
Beet b = new Beet();
}
}
}
Alpha.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
public class Alpha
{
public void Apple()
{
Console.WriteLine("From Alpha class A module");
}
}
}
Beta.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
public class Beta
{
public void Beet()
{
Console.WriteLine("From Beta class B module");
}
}
}
【问题讨论】:
-
Alpha a = new Alpha(); Beta b = new Beta(); a.Apple(); b.Beet(); -
Alpha a = new Alpha();和 Beta b = new Beta();
-
Alpha和Beta是类。Apple和Beet是这些类中的成员函数。