










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Lecture 12: C# Gotchas Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology
by Ben Albahari, Peter Drayton, and Brad Merrill, 2001 Great article: Jesse Liberty, “Top ten traps in C# for C++ programmers” www.ondotnet.com/pub/a/oreilly/dotnet /news/programmingCsharp_0801.html
using System; public class UnboxingTest { public static void Main() { int i = 123; //Boxing object o = i; // unboxing (must be explicit) int j = ( int ) o; Console.WriteLine("j: {0}", j); } } If o is null or not an int an InvalidCastException is thrown From Jesse Liberty, “Top ten traps in C# for C++ programmers,” www.ondotnet.com/pub/a/oreilly/dotnet/news/programmingCsharp_0801.html
public void Changer( ref int x) int aaronx; Aaron.Changer( ref int aaronx); C# will give a compile-time error
initialized
In general, variables in C# must be assigned before being passed into a function
public void Changer(out int x) int aaronx; Aaron.Changer( out int aaronx);
it’s OK for the value to be undefined
before the function returns!
~MyClass() { // your code to release unmanaged resources // used by object } is syntactic sugar for ~MyClass.Finalize { // your code to release unmanaged resources ///used by object base.Finalize(); } Your finalizer should not try to deal with other C# reference objects - only deal with unmanaged resources! Adapted from Jesse Liberty, “Top ten traps in C# for C++ programmers,” www.ondotnet.com/pub/a/oreilly/dotnet/news/programmingCsharp_0801.html
string [,] bingo; bingo = new string [3,2] {{“A”,”B”},{“C”,”D”},{“E”,”F”}}; bingo = new string [,] {{“A”,”B”},{“C”,”D”},{“E”,”F”}}; string [,] bingo = {{“A”,”B”},{“C”,”D”},{“E”,”F”}};
int [][]arr = new int[][] {new int[] {10,11,12}, new int[] {13, 14, 15, 16, 17}};