360 likes | 454 Views
C # Introduction Part 1. Which Visual Studio Should I use?. Any express (2010, 2012, 2013…) VS for Desktop Any full version. Which Visual Studio Should I use?. Any Express (2010, 2012, 2013…) VS for Desktop Any full version. .Net framework. Class Libraries … Console.ReadLine MSIL CLR.
E N D
Which Visual Studio Should I use? • Any express (2010, 2012, 2013…) VS for Desktop • Any full version
Which Visual Studio Should I use? • Any Express (2010, 2012, 2013…) VS for Desktop • Any full version
.Net framework • Class Libraries …Console.ReadLine • MSIL • CLR
HelloWord, scope {}, method, Main, white space using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; namespace First { classProgram { staticvoid Main(string[] args) { Console.WriteLine("Hello World!"); Console.ReadLine(); } } }
IDE, Projects, solutions, debug and release mode, … C:\Users\<yourname>\Documents\Visual Studio 2012\Projects .sln(open using Notepad -> it is xml) Look at using .csproj
C# .NET languages Compiling C/C++ old languages code.cs code.vb code.cpp C# compiler VB.NET compiler Intermediate Language (MSIL) + metadata Assembly language compiling Common Language Runtime (CLR) JIT compiler Machine language .exe Machine language .exe
Command Line compile and execution • C:\Windows\Microsoft.NET\Framework64\v4.0.30319 • csc.exe • cscProgram.cs
Comments, IntelliSense // . . . /* . . . */
Data Types, variables x = 2 y = x + 1; Console.WriteLine(y) … 3 Need Variables
Primitives (though they are Objects)http://msdn.microsoft.com/en-us/library/ms228360(v=vs.90).aspx String object
King System.Object char int string
isOperator* (will be later again) staticvoid Main(string[] args) { intmyInt = 5; TestIsOperator(myInt); stringmyString = "5"; TestIsOperator(myString); Console.ReadLine(); } privatestaticvoidTestIsOperator(Objectobj) { if (objisint) { inti = (int)obj; Console.WriteLine("Integer received"); } elseif (objisstring) { stringi = (string)obj; Console.WriteLine("String received"); } } }
Special Floating numbers (Division by 0)
Ex: float and decimal* (again later) using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespaceDoubleVsDecimal { classProgram { staticvoid Main(string[] args) { double a = 0.2f; double b = 1.0f; Console.WriteLine("{0}", a - b); decimal c = 0.2m; decimal d = 1.0m; Console.WriteLine("{0}", c - d); Console.ReadLine(); } } }output: -0.799999997019768 -0.8
Variable Scope *(again later) MyMethod
Back to our example: using integer data type int x = 2; int y = x + 1; Console.WriteLine(y);
Case sensitive language stringmyName; myName= "Andrew"; Console.WriteLine(myName); stringmyname = "Alice"; Console.WriteLine(myname); one line
Introducing var • Don’t be afraid varmyName1 = "Bill";
Conversion again* (again later). C# is a Strongly Typed Language string s = "Angie"; inttimes = 100; Console.WriteLine(times + s); string ok = times + s; intbad = times + s;