随笔 - 268  文章 - 0  评论 - 1028  阅读 - 160万

看到一个暴强的翻译,闲的蛋疼,写个c#版的

在豆瓣上看到一篇关于拿破仑的翻译,文科生的翻译有几段相当传神,不得不佩服汉语的强大。有好事者还用程序语言实现了一下,现已有java、python和html的版本,我也来写个渺小的C#版本,运行结果和java版是一致的,但是本文的这个稍作抽象(java版的我不觉得有多好,甚至应该说写得真烂),更符合C#程序员的阅读习惯。贴代码先:
【渺小滴C#版(知道运行结果又如何)】

复制代码
using System;
using System.Collections.Generic;

public abstract class Person
{
    
/// <summary>
    
/// name
    
/// </summary>
    public string Name { getset; }

    
/// <summary>
    
/// Chrysanthemum Damage Per Second
    
/// </summary>
    public int CDPM { getset; }
}

public class Enemy : Person
{

    
public Enemy(string name, int cdpm)
    {
        
this.Name = name;
        
this.CDPM = cdpm;
    }

    
public void Shout()
    {
        
if (this.CDPM > 0)
        {
            Console.WriteLine(
string.Format("{0} says: we are invincible!!!"this.Name));
        }
        
else
        {
            Console.WriteLine(
string.Format("{0} says: ......"this.Name));
        }
    }

    
public bool IsCanBeatNapoleon(Napoleon n)
    {
        
if (n == null)
        {
            
throw new ArgumentNullException("Napoleon was not initialized...");
        }
        
return this.CDPM > n.CDPM;
    }
}

public class Napoleon : Person
{
    
private IList<Enemy> enemies = new List<Enemy>();

    
private Napoleon()
    {
        
this.Name = "Napoleon";
        
this.CDPM = 100000;
        enemies.Add(
new Enemy("Italy"100));
        enemies.Add(
new Enemy("Egypt"100));
        enemies.Add(
new Enemy("Russia "100));
    }

    
private void Speak()
    {
        Console.WriteLine(
"My enemy number: " + enemies.Count);
        IList
<Enemy> trueEnemies = new List<Enemy>();
        
foreach (Enemy item in enemies)
        {
            
if (item.CDPM > CDPM)
            {
                trueEnemies.Add(item);
            }
        }

        Console.WriteLine(
"The number of enemies who can beat me: " + trueEnemies.Count);

        
foreach (Enemy item in enemies)
        {
            
do
            {
                item.Shout();
            }
            
while (item.IsCanBeatNapoleon(this));
        }
        Console.WriteLine(
"I am {0},my cdpm is {1}"this.Name, this.CDPM);
        Console.WriteLine(
"Dispose enemy list...");
        enemies.Clear();
        Console.WriteLine(
"Enemy list disposed!");
    }


    
static void Main(string[] args)
    {
        (
new Napoleon()).Speak();
        Console.Read();
    }
}
复制代码

最后,弱弱问一下,我怎么觉得程序实现的都和翻译无关呢? 比文科的翻译逊色不是一点点。

posted on   JeffWong  阅读(1247)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2010年10月 >
26 27 28 29 30 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 1 2 3 4 5 6

I know how to make it works and I want to know how it works.
点击右上角即可分享
微信分享提示