Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1.1 Basics: language constructs
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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" } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0.09 sec, absolute running time: 0.08 sec, cpu time: 0.08 sec, average memory usage: 16 Mb, average nr of threads: 4
edit mode
|
history
|
discussion
first five 1 2 3 1 2 3 1 2 3 3 2 1 yes