DNAunion2000: I am moving from Visual FoxPro to .NET and am working on setting up a base command/concept conversion reference for myself (others might find it handy too). If anyone sees any errors please point them out.
ANSI C++, C#, and Visual Basic.NET Command Mappings
Variable declaration/initialization (primitive data type):C++: int nAge = 29;C#: int nAge = 29; VB: Dim nAge As Integer = 29One-dimensional array declaration (primitive data type):C++: int testScores[10] ;C#: int[] testScores = new int[10] ;VB:' In VB you specify upper bound, not #of elements Dim testScores(9) As Integer Two-dimensional array declaration (primitive data type):C++: int testScores[5][10] ;C#: int[ , ] testScores = new int[5, 10] ;VB: Dim testScores(4, 9) As IntegerConditional branching: if…then…elseC++: if (x > 21) { // statements } else if (y < 50) { // statements } else { // statements }C#: if (x > 21) { // statements } else if (y < 50) { // statements } else { // statements }VB: If (x > 21) Then ‘ statements ElseIf (y < 50) ‘ statements Else ‘statements EndIf Conditional branching: switch/selectC++: switch (userSelection) { case ‘C’: case ‘c’: cout << “You chose to Continue.”; break; case ‘Q’: case ‘q’: cout << “You chose to Quit.”; break; default: cout << “Invalid selection…please try again.”; break; }C#: switch (userSelection) { case ‘C’: case ‘c’: Console.WriteLine(“You chose to Continue.”); break; case ‘Q’: case ‘q’: Console.WriteLine(“You chose to Quit.”); break; default: Console.WriteLine(“Invalid selection…please try again.”); break; }VB: (can you use: Case "C" OR "c"?) Select Case userSelection Case “C” Console.WriteLine(“You chose to Continue.”) Case “c” Console.WriteLine(“You chose to Continue.”) Case “Q” Console.WriteLine(“You chose to Quit.”) Case “q” Console.WriteLine(“You chose to Quit.”) Case Else Console.WriteLine(“Invalid selection…please try again.”)End SelectIteration: For loopC++: for (int Lcv = 1; Lcv <= 10; Lcv++) { // statements }C#: for (int Lcv = 1; Lcv <= 10; Lcv++) { // statements }VB: For Lcv As Integer = 1 To 10 Step 1 ‘ statements Next LcvIteration: While loopC++: int Lcv = 1; while (Lcv <= 10) { // statements Lcv++; }C#: int Lcv = 1; while (Lcv <= 10) { // statements Lcv++; }VB: Dim Lcv As Integer = 1 While (Lcv <= 10) ‘ statements Lcv += 1 End
removed emoticons Edited by: *narf* at: 7/6/03 2:41 pm