CLR 如何知道要调用哪个方法,因为它们返回不同的值(一个是 void,另一个是 int)?从重载的意义上来说,这也是不对的,具有相同参数但返回类型不同的方法。
例子:
class Program
{
static int Main(String[] args) //Main with int return type but Parameter String[] args
{
return 0;
}
/* this main method also gonna get called by CLR even though return type void and Same parameter String[] args.
static void Main(String[] args) //Main with int return type but String[] args
{
} */
private static void func(int one)
{
Console.WriteLine(one);
}
private static int func(int one) //compiler error. two overloaded method cant have …
Run Code Online (Sandbox Code Playgroud) 当我尝试在int数组中打印值的平均值时会出现什么问题,并且它打印出的值与我的值完全不同.
int[] numbers;
numbers = new int[5];
Console.WriteLine("give five integer numbers:");
numbers[0] = Int32.Parse(Console.ReadLine());
numbers[1] = Int32.Parse(Console.ReadLine());
numbers[2] = Int32.Parse(Console.ReadLine());
numbers[3] = Int32.Parse(Console.ReadLine());
numbers[4] = Int32.Parse(Console.ReadLine());
int sum = 0;
foreach (int x in numbers) {
sum += x;
int aver = sum / numbers.Length;
Console.WriteLine("average: {0}",aver);
}
Run Code Online (Sandbox Code Playgroud) 我也试着让我的C#控制台应用程序发出哔哔声.是的我知道我可以使用Console.Beep但我也想降低音量等.
但我得到的错误是这样的:
预期的方法名称
在这条线上:
binaryWriter.Write(hdr(i));
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
private bool Beep(int volume, int frequency, int duration)
{
try
{
double amplitude = volume * 1.27;
double a = ((amplitude * (System.Math.Pow(2, 15))) / 1000) - 1;
double deltaFt = 2 * System.Math.PI * frequency / 8000;
double samples = 441 * (duration / 100);
int bytes = Convert.ToInt32(samples) * 4;
int[] hdr = {
0x46464952,
36 + bytes,
0x45564157,
0x20746d66,
16,
0x20001,
8000,
176400,
0x100004,
0x61746164,
bytes
};
using (System.IO.MemoryStream memoryStream = …
Run Code Online (Sandbox Code Playgroud)