190 likes | 271 Views
ECE 264 Class 1-2. P. Viall Fall 2014. What is .NET?. platform for developing applications NOT Microsoft specific (but designed by Microsoft Versions run on Linix (Max), iPhone , and Android In theory, multiple languages may be used C# made up of the best components of C++ and Java.
E N D
ECE 264 Class 1-2 P. Viall Fall 2014
What is .NET? • platform for developing applications • NOT Microsoft specific (but designed by Microsoft • Versions run on Linix (Max), iPhone, and Android • In theory, multiple languages may be used • C# made up of the best components of C++ and Java
What is the .NET framework? • giant library of code (for your use) • CLR – Common Language Runtime • CTS – Common Type System (basic data types)
How are applications compiled? Step 1 “Assembly” (Non-OS/non-machine specific code) Compilaiton to CIL (Common Intermediate Language) C# Program Step 2 “Assembly” (Non-OS/non-machine specific code) Native Code (Machine and OS specific executable) JIT (Just In Time) Compiler
About Managed Code System Runtime .NET CLR (Common Language Runtime) Native Code Native Code Native Code C# is (by default) MANAGED CODE...that is the CLR checks each operation to insure it will not overwrite anything it shouldn’t (array bounds, system space, etc.). It is possible to mark code as “unsafe” and allow it to do anything.
What can you do with C# • Console applications (dos box) • Desktop (windows) applications with menus, dialog boxes, buttons, etc. • Windows Store applications – designed for touch devices • Web applications – anything viewed through a web browser • WCF (Windows Communication Foundation) for use in distributed (networked) applications
Naming of variables • Same as C except variables may start with @ • Naming convention is either PascalCase or camelCase • PascalCasecapitolized the first letter of each word (used for name spaces and object types) • camelCase is the same except first word is not capitolized. (used for variables)
Arithmetic Operations & Namespaces • Same as C ( +, -, *, /, %, ++, --, =, +=, -=, *=, /=, %=) • Precedence is same as C • Namespaces are a way to compartmentalize scope of variables (similar to how functions compartmentalize). HOWEVER, you can access a variable in a different namespace by specifying the entire name (namespace.variablename). If namespaces are nested (one inside the other), you need to specify both namespaces and variable name (namespace1.namespace2.variablename)
&, |, !, ^ with bool values • & = logical and • | = logical or • ! = logical not • ^ = logical xor • &=, |=, ^= are also allowed
&, |, ~, ^ with integer values • Are bitwise instructions...each individual pair of bits in the integer are evaluated separately • & = bitwise and • | = bitwise or • ~ = bitwise not (compliment) • ^ = bitwise xor • &=, |=, ^= are also allowed
bitwise example intmyColor = 0; boolcontainsRed; myColor = myColor | 2; // add green myColor = myColor | 4; // add red myColor = myColor & (~2); // remove green containsRed = (myColor & 4) == 4;
More statements Ternary Operator <test> ? <result if true> : <result if false> Example: big = (a>b)?a:b; if ( ) – same as C if () else – same as C do { } while (condition) – same as C while { } – same as C for ( ) { } – same a C break, continue – same as C
switch – almost like C except static void Main(string[] args) { const string myName = “kirk"; const string uncommonName= “sherajeseb"; const string sillyName = “miles"; string name; Console.WriteLine("What is your name? "); name = Console.ReadLine(); switch (name.ToLower()) { case myName: Console.WriteLine("You have the same name as me"); break; case sexyName: Console.WriteLine(“What an uncommon name!"); break; case sillyName: Console.WriteLine("That's a silly name."); break; } Console.WriteLine("Hello {0}!", name); Console.ReadKey(); }