.net syntax - mkol/il2js GitHub Wiki

Object-Oriented Programming (OOP)

Following .NET OOP features are supported:

  • class inheritance
  • interfaces (user-defined only)
  • virtual and/or abstract methods
  • static constructors

ref and out parameters

ref and out parameters are supported:

void refExample(ref int param0, out int param1) {
// do something here, set param1 value
}

foreach statement

foreach loop for arrays and lists is supported:

void foreachExample(int[] ints, List<string> strings, IEnumerable<double> doubles) {
  foreach(var item in ints) {
	// do something
  }
  foreach(var item in strings) 
	// do something
  }
  foreach(var item in doubles) 
	// do something
  }
}

Limitations

Non generic IEnumerable and IEnumerator are not supported in the Framework. Use IEnumerable<object> and IEnumerator<object> instead.

LINQ

LINQ syntax is supported as most of Enumerable methods are supported.

In following example compiler generates the same IL code for both methods

void LINQTest0(IEnumerable<string> strings){
  foreach(var data in from s in strings
					  where s.Length>2
					  select new {
						First=s.Substring(0,2),
						Second=s.Substring(2),
					  }){
	// do something
  }
}
void LINQTest1(IEnumerable<string> strings){
  foreach(var data in strings
					  .Where(s=>s.Length>2)
					  .Select(s=> new {
						First=s.Substring(0,2),
						Second=s.Substring(2),
					  }){
	// do something
  }
}

lock statement

lock block is supported:

void lockExample() {
  lock(this){
	// do something
  }
}

yield statement

yield is supported as a way to create IEnumerable<> and IEnumerator<>.

static IEnumerator<string> YieldEnumerator() {
	for (char c = 'a'; c <= 'c'; ++c) {
		yield return c.ToString();
	}
}
static IEnumerable<string> YieldEnumerable() {
	for (char c = 'a'; c <= 'c'; ++c) {
		yield return c.ToString();
	}
}

Limitations

Non generic IEnumerable and IEnumerator are not supported in the Framework. Use IEnumerable<object> and IEnumerator<object> instead.

See also

[.net methods] [threads]

⚠️ **GitHub.com Fallback** ⚠️