C#的运算符的重载
来源:百度知道 编辑:UC知道 时间:2024/06/10 09:39:16
using System;
{
class Program
{
int c = 3;
public static Program operator ++(a b)
{
b × c = b × c + 2;
return b;
}
static void Main()
{
Program y = new Program();
y++;
Console.WriteLine(y.c );
}
}
}
运算符的重载 C#的 书上写了 我怎么编译不出来 要报错呢
高手些 指点哈
{
class Program
{
int c = 3;
public static Program operator ++(a b)
{
b × c = b × c + 2;
return b;
}
static void Main()
{
Program y = new Program();
y++;
Console.WriteLine(y.c );
}
}
}
运算符的重载 C#的 书上写了 我怎么编译不出来 要报错呢
高手些 指点哈
第一点++是单目运算符,只能有一个参数,正确如下
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
namespace Consoletest
{
public class Program
{
public Program ()
{
}
int c = 3;
public static Program operator ++(Program b)
{
b.c = b.c + 2;
return b;
}
static void Main()
{
Program y = new Progr