C Sharp: Difference between revisions
No edit summary |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 44: | Line 44: | ||
ManualResetEvent finishedHandle = new ManualResetEvent(false); | ManualResetEvent finishedHandle = new ManualResetEvent(false); | ||
for (int i = 0; i < numberOfTasks; i++) { | for (int i = 0; i < numberOfTasks; i++) { | ||
// Note that you cannot reuse i here. | |||
// You can use this trick to put it in a closure | |||
// Or you can make a closure manually with another anonymous function | |||
// i.e. (a => { return _=>{ \\ Do stuff here })(a) | |||
int j = i; | int j = i; | ||
ThreadPool.QueueUserWorkItem(_ => { | ThreadPool.QueueUserWorkItem(_ => { | ||
| Line 65: | Line 69: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Memory Management== | |||
C# has value types and reference types. Reference types are heap allocated similar to Java. Value types are allocated either on the stack or within objects on the heap, the same as primitives in Java or structs in C/C++. | |||
Reference types are created with classes. Value types are created with structs. | |||
==Platform Invoke== | ==Platform Invoke== | ||
[https://docs.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke Reference]<br> | [https://docs.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke Reference]<br> | ||
Platform Invoke (or P/Invoke) allows you to call and use C and C++ libraries from within your C# or other .NET programs. | Platform Invoke (or P/Invoke) allows you to call and use C and C++ libraries from within your C# or other .NET programs. | ||
[[Category:Programming languages]] | |||