C#编程错误 初学者询问

来源:百度知道 编辑:UC知道 时间:2024/06/22 07:35:31
using System;
using System.Collections.Generic;
using System.Text;
namespace Chap03
{
class Program
{
static void Swap(out int x, out int y)
{
int x = 3;
int y = 2;
int c = 0;
if (x > y)
{
c = x;
x = y;
y = c;
}
}
static void Main()
{
int x;
int y;

Swap(out x, out y);
Console.WriteLine("x的值是{0},y的值为{1}", x, y);
Console.ReadLine();

}
}
}

说是不止一个入口?????

using System;
using System.Collections.Generic;
using System.Text;
namespace Chap03
{
class Program
{
static void Swap(out int x, out int y)
{
x = 3;
y = 2;
int c = 0;
if (x > y)
{
c = x;
x = y;
y = c;
}
}
static void Main()
{
int x;
int y;

Swap(out x, out y);
Console.WriteLine("x的值是{0},y的值为{1}", x, y);
Console.ReadLine();

}
}
}

这样可以正常运行,你应该是重复定义了变量吧,导致同一变量的歧义

如果你是用VC#做的话,c#的main在program.cs这个文件中,你这里相当于定义了一个新main,所以就是2个程序入口了

不知听哪位高手说的。
入口函数,只能是静态函数并且类型为void 或 int 的大小写正确的 Main,可以有参数。
要想验证说法是否正确,你可以分别在两个函数中开两个窗体,看究竟是一个还是两个!

Main()函数所在的文件名并不重要,关键是你只有