Csharp Differences from JS
Note: text copied from a Unity Answers question: Syntax Differences in C#/JS
Unity's Guide to C# Scripting
First, here is Unity's C# list: Writing Scripts in C#. It covers things like differences in coroutine syntax, etc.
Other Differences in C#
s_LevelManager slm = tmp.GetComponent<s_LevelManager>(); int count = slm.getMyCount();
}</csharp> Note: unity iphone 1.6 now supports generics (it didn't before). If you want a more complete definition of Generics: MS Introduction to C# Generics
The Foreach Keyword
C# Iterators use foreach instead of for: <csharp>for (var x in someList) //JS
x.someVar = true;
foreach (GameObject x in someList) //C#
x.someVar = true;</csharp>
The New Keyword
In JS when creating a new object by calling its Class name, you just use the Class name, whereas C# requires the new keyword. Note - this includes creating new objects inside function calls: <csharp>var foo = Vector3(0,0,0); // JS Vector3 foo = new Vector3(0,0,0); // C# Instantiate(someObj, new Vector3(0,0,0), someRotation); // C#</csharp>
Speaking of Instantiate() - it requires casting to use the returned object: <csharp>GameObject foo = Instantiate(someObj...); // JS GameObject foo = (GameObject) Instantiate(someObj...); // C# GameObject foo = Instantiate(someObj...) as GameObject; // C#2 </csharp> Note that there are two different ways of casting in C#. For the first line above - if the object can't be instantiated, it will throw an Exception. You would need to use a try/catch to properly handle it. The second line, if it fails, will set foo to null, and not throw an Exception. Then you would just need to test if the returned object was null or not.
Properties with Getters/Setters
In C#, it's possible to define special functions that can be accessed as if they were variables. For instance, I could say foo.someVar = "testing";, and under the hood, there's a get and set function that process the argument "testing" and store it internally. But - they could also do any other processing on it, for instance, capitalizing the first letter before storing it. So you're not just doing a variable assignment, you're calling a function that sets the variable, and it can do - whatever functions do.