Boo vs C # Language Comparison 6

Source: Internet
Author: User
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 (50 ms)

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)

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 t:

Print "error happened"

Try

{

// Do something

}

Catch

{

Console. writeline ("error

Happened ");

}

Try:

# Do something

Except t e as soapexception:

Print E. Detail

Except t e:

Print E

Try

{

// Do something

}

Catch (soapexception E)

{

Console. writeline (E );

}

Catch (exception E)

{

Console. writeline (E );

}

Try:

# Do something

Except t e:

Print E

Ensure:

Print "done"

Try

{

// Do something

}

Catch (exception E)

{

Console. writeline (E );

}

Finally

{

Console. writeline ("done ");

}

Try:

# Do something

Except t 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

}

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.