Boo Vs C# 语言对比 6

简介: keywords Boo syntax C# equivalent class Car: pass pass keyword ...

 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

}

相关文章
|
存储 开发框架 .NET
C#语言究竟隐藏了哪些秘密?一文带你揭开编程界的神秘面纱
【8月更文挑战第22天】C#是微软推出的面向对象编程语言,以其简洁的语法和强大的功能,在软件开发领域占据重要地位。作为一种强类型语言,C#确保了代码的可读性和可维护性。它支持多种数据类型,如整型、浮点型及复合类型如类和结构体。类是核心概念,用于定义对象的属性和行为。C#还包括方法、异常处理、集合类型如列表和字典,以及泛型和LINQ等高级特性,支持异步编程以提高应用响应性。.NET Core的推出进一步增强了C#的跨平台能力。
321 3
|
JSON C# 开发者
C#语言新特性深度剖析:提升你的.NET开发效率
【10月更文挑战第15天】C#语言凭借其强大的功能和易用性深受开发者喜爱。随着.NET平台的演进,C#不断引入新特性,如C# 7.0的模式匹配和C# 8.0的异步流,显著提升了开发效率和代码可维护性。本文将深入探讨这些新特性,助力开发者在.NET开发中更高效地利用它们。
355 1
|
存储 开发框架 .NET
C#语言如何搭建分布式文件存储系统
C#语言如何搭建分布式文件存储系统
485 2
|
前端开发 Java C#
C#语言的优缺点?
C#语言的优缺点?
1024 4
|
监控 安全 C#
C# 语言助力员工监控系统的完善
在数字化时代,企业日益重视员工管理的效率与精准度,员工监控系统因此成为提升管理水平的有效工具。C# 语言凭借其简洁、高效和安全的特点,在开发此类系统中扮演了重要角色,可实现实时监控员工电脑操作、网络行为及工作时间统计等功能,从而提高工作效率并保障企业利益。同时,企业在应用这些技术时也需关注员工隐私权的保护。
210 6
|
IDE C# 开发工具
C# 语言的主要优势是什么?
C# 语言的主要优势是什么?
962 2
|
安全 IDE Java
C#语言的
C#语言是一种面向对象的编程语言
422 1
|
JSON C# 开发者
💡探索C#语言进化论:揭秘.NET开发效率飙升的秘密武器💼
【8月更文挑战第28天】C#语言凭借其强大的功能与易用性深受开发者喜爱。伴随.NET平台演进,C#持续引入新特性,如C# 7.0的模式匹配,让处理复杂数据结构更直观简洁;C# 8.0的异步流则使异步编程更灵活高效,无需一次性加载全部数据至内存。通过示例展示了模式匹配简化JSON解析及异步流实现文件逐行读取的应用。此外,C# 8.0还提供了默认接口成员和可空引用类型等特性,进一步提高.NET开发效率与代码可维护性。随着C#的发展,未来的.NET开发将更加高效便捷。
247 1
|
C++ 安全 存储
C++智能指针解析
C++智能指针解析
459 0
C++智能指针解析
|
设计模式
结构型设计模式
结构型设计模式
305 0
结构型设计模式