zoukankan      html  css  js  c++  java
  • Boo Vs C# 语言对比 6

     keywords

    Boo syntax

    C# equivalent

    class Car:

    pass

    pass keyword

    public class Car

    {

    }

    employee is null

    employee == null

    "foo" is "bar"

    employee isa Manager

    ReferenceEquals("foo","bar")

    employee is Manager

    employee is not null

    employee != null

    not employee.IsTemporary

    !employee.IsTemporary

    employee is not null and

    employee isa Manager

    employee != null &&

    employee is Manage

    employee isa Manager or not

    employee.IsTemporary

    (employee is Manager) ||

    (!employee.IsTempor

    cast(int, variable)

    (int)variable

    name = variable as string

    string name = variable as string;

    typeOfString = typeof(string)

    Type typeOfString = typeof(string);

    typeOfString = string

    Type typeOfString = typeof(string);

    Conditionals

    if lives == 0:

    print "game over"

    if (lives == 0)

    Console.WriteLine("game over");

    if lives == 0:

    print "game over"

    game.Finish()

    if( lives == 0)

    {

    Console.WriteLine("game over");

    game.Finish();

    }

    if not lives:

    print "game over"

    if (lives == 0)

    Console.WriteLine("game over");

    unless lives:

    print "game over"

    if (lives == 0)

    Console.WriteLine("game over");

    print "game over" unless lives

    print "game over" if lives == 0

    if (lives == 0)

    Console.WriteLine("game over");

    if lives == 0:

    print "game over"

    else:

    print "carry on"

    if (lives == 0)

    Console.WriteLine("game over");

    else

    Console.Writeline("carry on");

    if lives == 0:

    print "game over"

    elif lives == 1:

    print "Last life"

    else:

    print "carry on"

    if (lives == 0)

    Console.WriteLine("game over");

    else if (lives == 1)

    Console.WriteLine("last life")

    else

    Console.Writeline("carry on");

    Loops and iterations

    while lives != 0:

    PlayRound()

    while(lives!=0)

    PlayRound();

    for i in range(0,10):

    print i

    for(int i=0;i<10;i++)

    Console.WriteLine(i);

    for user in users:

    print user.Name

    for user in users:

    if user.Name is null:

    continue

    print user.Name

    foreach(User user in users)

    Console.WriteLine(user.Name);

    foreach(User user in users)

    {

    if(user.Name == null)

    continue;

    Console.WriteLine(user.Name);

    }

    index = 0

    for user in users:

    break if index > 10

    print user.Name

    index += 1

    int index = 0;

    foreach(User user in users)

    {

    if(index > 10)

    break;

    Console.WriteLine(user.Name);

    index += 1;

    }

    while ie.Busy:

    Thread.Sleep(50ms)

    while( ie.Busy)

    Thread.Sleep(50);

    Type declarations

    class Car:

    wheels as int

    defStartEngine():

    pass

    public class Car

    {

    protected int wheels;

    public void StartEngine()

    {

    }

    }

    internal class Car:

    pass

    internal class Car {}

    struct Point:

    X as int

    Y as int

    public struct Point

    {

    public int X;

    public int Y;

    }

    class Truck(Car):

    pass

    public class Truck : Car

    {

    }

    class Car(IDisposable):

    def Dispose():

    pass

    public class Car : IDisposable

    {

    public void Dispose()

    {

    }

    }

    enumTddStages:

    Red

    Green

    Refactor

    public enumTddStages

    {

    Red,

    Green,

    Refactor

    }

    Methods, properties, and control structures

    def Start():

    pass

    public void Start()

    {

    }

    def Start(async as bool):

    pass

    public void Start(boolasync)

    {

    }

    def Start(async as bool) as

    WaitHandle:

    raise NotImplementedException()

    public WaitHandle Start(boolasync)

    {

    throw new

    NotImplementedException();

    }

    defGetInteger():

    return 1

    public intGetInteger()

    {

    return 1;

    }

    defSetItem(key,val):

    pass

    public void SetItem(object key, object val)

    {

    }

    defVarArgs(*args as (object)):

    pass

    VarArgs(1, "foo")

    public void VarArgs(params object[]

    args)

    {

    }

    Name:

    get:

    return "Boo"

    public string Name

    {

    get { return "C#"; }

    }

    Email:

    get:

    return email

    set:

    email = value

    Email:

    get: return email

    set: email = value

    public string Email

    {

    get { return email; }

    set { email = value; }

    }

    [property(Email)]

    email as string

    public string Email { get; set; }

    xml = XmlDocument()

    XmlDocument xml = new XmlDocument()

    emp = Employee(Name: "foo", Id: 15)

    varemp = new Employee{ Name = "foo",

    Id = 15};

    class Car():

    def constructor():

    print "Car created!"

    public class Car

    {

    public Car()

    {

    Console.WriteLine("Car

    created!");

    }

    }

    class Car():

    def destructor():

    print "died"

    public class Car

    {

    public ~Car()

    {

    Console.WriteLine("died");

    }

    }

    raise NotImplementedException()

    throw new NotImplementedException();

    raise "error happened"

    throw new Exception("error happened");

    try:

    # do something

    except:

    print "error happened"

    try

    {

    // do something

    }

    catch

    {

    Console.WriteLine("error

    happened");

    }

    try:

    # do something

    except e as SoapException:

    print e.Detail

    except e:

    print e

    try

    {

    // do something

    }

    catch(SoapException e)

    {

    Console.WriteLine(e);

    }

    catch(Exception e)

    {

    Console.WriteLine(e);

    }

    try:

    # do something

    except e:

    print e

    ensure:

    print "done"

    try

    {

    // do something

    }

    catch(Exception e)

    {

    Console.WriteLine(e);

    }

    finally

    {

    Console.WriteLine("done");

    }

    try:

    # do something

    except e:

    print e

    raise

    try

    {

    // do something

    }

    catch(Exception e)

    {

    Console.WriteLine(e);

    throw;

    }

    save.Click += do(sender,e):

    print "Clicked"

    save.Click += delegate(

    object sender,

    EventArgs e

    )

    {

    Console.WriteLine("Clicked");

    }

    save.Click += { print "Clicked" }

    save.Click += (sender, e) =>

    Console.WriteLine("Clicked");

    myList.Find( { i | i > 5 })

    myList.Find(delegate(int i)

    {

    return i> 5;

    });

    namespace Foo.Bar.Baz

    class Foobar:

    pass

    namespace Foo.Bar.Baz

    {

    public class Foobar

    {

    }

    }

    self.name = "foo";

    this.name = "foo";

    super.name = "foo";

    base.name = "foo";

    # single line comment

    // and this is one as well

    /*

    And here is a multi

    line comment

    */

    // single line comment

    /*

    Multi line comment

    */

    Useful macros

    assert user is not null

    Debug.Assert( user != null, "user is

    not null"

    print "foo"

    Console.WriteLine("foo")

    using db = RhinoConnection():

    pass

    using(RhinoConnectiondb = new

    RhinoConnection())

    {

    }

    lock syncLock:

    #code under lock

    lock(syncLock)

    {

    // code under lock

    }

  • 相关阅读:
    WebDriver(C#)之十点使用心得
    selenium加载cookie报错问题:selenium.common.exceptions.InvalidCookieDomainException: Message: invalid cookie domain
    c#和javascript函数的相互调用(ObjectForScripting 的类必须对 COM 可见。请确认该对象是公共的,或考虑向您的类添加 ComVisible 属性。)
    开源项目推荐:Qt有关的GitHub/Gitee开源项目
    Github Qt开源项目
    QCefView实现与JS的交互
    UE4 Subsystems
    Docker与k8s的恩怨情仇(八)——蓦然回首总览Kubernetes
    表格技术七十二变|手把手教你用Canvas电子表格做电子签名
    应用程序如何通过嵌入式分析技术获益
  • 原文地址:https://www.cnblogs.com/2018/p/2623630.html
Copyright © 2011-2022 走看看