Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1.1 Basics: language constructs
//1.1 Basics: language constructs using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //if if(5>3) { Console.WriteLine("first"); } else { Console.WriteLine("second"); } //switch int a = 5; switch(a) { case 1: Console.WriteLine("one"); break; case 5: Console.WriteLine("five"); break; default: break; } //C-style for List<int> list = new List<int>() {1,2,3}; for(int i=0; i<list.Count(); i++) { Console.Write("{0} ", list[i]); } //foreach Console.WriteLine(); foreach(int item in list) { Console.Write("{0} ", item); //list.Add(7); //can't modify collection you are iterating through! If you need that use C-style for } //Linq-style foreach Console.WriteLine(); list.ForEach(f => Console.Write("{0} ", f)); //ok, that's not basic construct and it will be talked about later, however id does the same as above //while Console.WriteLine(); while(list.Count() > 0) { Console.Write("{0} ", list.Count()); list.RemoveAt(0); } //Conditional statement Console.WriteLine(); Console.WriteLine(5 > 3 ? "yes" : "no"); //short equivalent to if(5>3) return "yes" else return "no" } } }
run
|
edit
|
history
|
help
1
seoituerwoi
Prueba
linq jean by Fausto
Helloworld
SHA tester
first test
Plt-D v.0.9.3.1
money
Testing 008
Remove Duplicates - Asif Ali