Let's program in Chinese

Source: Internet
Author: User
Let's program in Chinese

I suddenly thought that C # should support Chinese programming, because it supports Unicode of source code, so I wrote a small program in Chinese to see if it can be compiled and executed. The result is exactly as expected, it can be executed. Although the Code has no practical value, it is very interesting. I want to use such a small program to teach a Chinese student to learn object-oriented, which may be lower and more interesting. After all, it is a mother tongue. (For a slight correction, you can use the runtime class identification to determine "who I am ")

The source code of the program is:

Using System;

Namespace Chinese programming
{
Public class creature
{
Public virtual void ()
{
Console. WriteLine ("I am... succeeded? What am I? I don't know what I am, but I am a "+ this. GetType (). Name );
}
}
Public class animal: creature
{
Protected string movement mode;
Protected string quantifiers = "only ";
Public animal ()
{
Mobile mode = "mobile ";
}
Public virtual void mobile ()
{
Console. WriteLine ("this" + quantizer + this. GetType (). Name + "at will" + mobile mode + Environment. NewLine );
}
Public override void ()
{
Console. writeLine ("I belong to" + this. getType (). baseType. name + ", I am a" + quantizer + "cute" + this. getType (). name );
}
}
Public class bird: Animal
{
Public bird ()
{
Moving Mode = "Flying ";
}
}
Public class fish: Animals
{
Public fish ()
{
Mobile mode = "traveling ";
Quantifiers = "entries ";
}
}
Public class horse: Animal
{
Public horse ()
{
Mobile mode = "running ";
Quantifiers = "horse ";
}
}
Run sealed public class
{
[STAThread]
Static void Main (string [] args)
{
Creature [] zoo = new creature [5];
Zoo [0] = new bird ();
Zoo [1] = new fish ();
Zoo [2] = new horse ();
Zoo [3] = new animal ();
Zoo [4] = new creature ();
Foreach)
{
Little creature. self-introduction ();
If (small creature is animal)
{
(Animal) small creature). Move ();
}
}
}
}
}

The execution result of this program is:

D:/Project/C #/MyTest/Chinese programming/bin/Debug> Chinese programming .exe
I belong to animals. I am a cute bird.
This bird is flying freely. I belong to an animal. I am a lovely fish.
The fish traveled freely
I belong to animals, and I am a cute horse.
This horse is running freely. I belong to a creature. I am a cute animal.
This animal is moving freely. I am... why? What am I? I don't know what I am, but I am a creature.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.