by Joel Limardo
Home | Twitter | LinkedIn | Consulting | About | RSS | Map
Areas:
Process
 
Technical
 
Projects:


Sat, 29 Aug 2015

While Loop

 csharp> while (n > 0) { print ("the value is " + n ); n--; }
the value is 10 the value is 9 the value is 8 // ... the value is 1


posted at: 23:50 | path: /technical/programming/DOTNET | this entry | top

For Loop

 csharp> for (int n = 1; n >= 10; n = n + 1) { print (n); }
// Returns nothing csharp> for (int n = 1; n <= 10; n = n + 1) { print (n); } 1 2 3 // ... 10

Remember that the for loop condition says, 'do this while this statement returns true.'



posted at: 23:50 | path: /technical/programming/DOTNET | this entry | top

If/Then

 csharp> bool a = true;
csharp> if (a) { print("it is true") } else { print ("it is false") }; {interactive}(1,30): error CS1525: Unexpected symbol `}', expecting `;' {interactive}(1,61): error CS1525: Unexpected symbol `}', expecting `;' csharp> if (a) { print("it is true"); } else { print ("it is false"); } it is true csharp> a = false; csharp> if (a) { print("it is true"); } else { print ("it is false"); } it is false


posted at: 23:49 | path: /technical/programming/DOTNET | this entry | top

Arrays

 csharp> int[] mArr = new int[5];                                          
csharp> for (int i = 0; i <= 4; i++) { mArr[i] = i * 3; print (mArr[i]);} 0 3 //.. 12 csharp> int []mArr = {1*9,2*9, 3*9, 4*9, 5*9, 6*9}; csharp> for (int i = 0 ; i <= 5; i++) { print (mArr[i]); } 9 18 //.. 54 csharp> foreach (int item in mArr) { print (item); } 9 /.. 54

Multi-dimensional:

int[] m = System.Int32[]
int[,] p = System.Int32[,]
char[,] pg = System.Char[,]


posted at: 15:15 | path: /technical/programming/DOTNET | this entry | top

Switch Statement

 csharp> switch(it) {
> case true : > print ("it is true"); > break; > case false: > print ("It is false"); > break; > default: > print ("no idea"); > break; > }


posted at: 14:49 | path: /technical/programming/DOTNET | this entry | top

Simple Casting

 csharp> long lVal = 1000;
csharp> int sf; csharp> sf = lVal; {interactive}(1,5): error CS0266: Cannot implicitly convert type `long' to `int'. An explicit conversion exists (are you missing a cast?) csharp> sf = (int)lVal; csharp> print (sf); 1000


posted at: 14:26 | path: /technical/programming/DOTNET | this entry | top

© 2015-2017. All Rights Reserved. All original code appearing on this site is MIT Licensed unless otherwise noted.