一直听说过“易语言”,但是也一直都没用过,只是听说可以用纯中文就能编程,从网上找到的教程看非常适合初学者。
这里让我们看看有没有办法让高级语言c#也支持个中文编程,首先让我们看如下代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace ChineseCode
{
public class 生物
{
public virtual void 自我介绍()
{
Console.WriteLine("我是
咦?我是什么?我也不知道我是什么,反正我是一个" + this.GetType().Name);
}
}
public class 动物 : 生物
{
protected string 移动方式;
protected string 量词 = "只";
public 动物()
{
移动方式 = "移动";
}
public virtual void 移动()
{
Console.WriteLine("这" + 量词 + this.GetType().Name + "在自由自在的" + 移动方式 + Environment.NewLine);
}
public override void 自我介绍()
{
Console.WriteLine("我属于" + this.GetType().BaseType.Name + ", 我是一" + 量词 + "可爱的" + this.GetType().Name);
}
}
public class 鸟 : 动物
{
public 鸟()
{
移动方式 = "飞翔";
}
}
public class 鱼 : 动物
{
public 鱼()
{
移动方式 = "游来游去";
量词 = "条";
}
}
public class 马 : 动物
{
public 马()
{
移动方式 = "奔跑";
量词 = "匹";
}
}
sealed public class 运行
{
[STAThread]
static void Main(string[] args)
{
生物[] 动物园 = new 生物[5];
动物园[0] = new 鸟();
动物园[1] = new 鱼();
动物园[2] = new 马();
动物园[3] = new 动物();
动物园[4] = new 生物();
foreach (生物 小生物 in 动物园)
{
小生物.自我介绍();
if (小生物 is 动物)
{
((动物)小生物).移动();
}
}
Console.ReadKey();
}
}
}本来我想能不能连Int这种关键字都用中文代替,不过C#貌似没有提供类似typedef这个功能,所以暂时也就不管了。
且看运行效果:
接下来我在C++ VS 2005环境下也测试了下中文变量,貌似还要BT:
#include <iostream>
using std::endl;
using std::cin;
using std::cout;
int main()
{
typedef int 中文测试;
中文测试 测试=0;
测试++;
cout<<测试<<endl;
getchar();//防止直接退出
}用typedef将int型变量定义为中文测试后更加像中文编程鸟,哈哈。而且运算符用在上面也没什么问题。
虽然我并不建议这么额定义变量,但是有时候一些小程序小问题,特别是当超级电白问你这句代码什么意思,这个程序该怎么写的时候,用中文解释可能更加方便。
此文纯属娱乐嬉戏,使用中文变量导致任何问题不要来找我哦,呵呵。

浙公网安备 33010602011771号