如何将其从Python转换为C# [英] How do I convert this from Python to C#
问题描述
您好!我不是程序员,但我想给一个人一个惊喜。我看到这个代码在蛋糕上阅读,并希望写相同,但在C#上。我尝试在谷歌中找到类似它的转换器,但却失败了。任何人都可以帮我吗?非常感谢:)
我尝试过:
# - * - 编码:utf-8 - * -
类人类(对象):
def__init __(自我,姓名,年龄) :
self.name =姓名
self.age =年龄
def happyBirthday(self):
如果self.age == 30:
打印'生日快乐',自我姓名,'!'
coolDude =人类('John',30)
coolDude.happyBirthday()
Hello! I am not programmer, but I want to make a surprise for one person. I saw this code on cake to read and want to write the same, but on C#. I try to found converter of something like it in Google but falled. Can anybody help me with this? Thank you very much :)
What I have tried:
# -*- coding: utf-8 -*-
class Human(object):
def__init__(self, name, age):
self.name = name
self.age = age
def happyBirthday(self):
if self.age == 30:
print 'Happy Birthday, ', self.name, '!'
coolDude = Human('John', 30)
coolDude.happyBirthday()
推荐答案
public class Human
{
public string Name { get; private set;}
public int Age{ get; private set;}
public Human(string name, int age)
{
Name = name;
Age = age;
}
public void HappyBirthday()
{
if (Age == 30)
Console.WriteLine(
生日快乐{Name}!);
}
}
public static class 问候语
{
public static < span class =code-keyword> void Main()
{
Human coolDude = Human( John, 30 );
coolDude.HappyBirthday();
}
}
"Happy Birthday {Name}!"); } } public static class Greetings { public static void Main() { Human coolDude = Human("John", 30); coolDude.HappyBirthday(); } }
这篇关于如何将其从Python转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!