Introduction to C# and DB programming using ADO.NET Shahin Shayandeh October 2007 Outline (cid:134) .NET Framework (cid:134) Object Oriented Programming (OOP) (cid:134) C# basics (cid:134) Database programming using ADO.NET .NET Framework (cid:134) Development Languages (cid:132) C++, C#, J#, Python, Perl, … (cid:134) Integrated Development Environment (IDEs) (cid:132) Visual Studio .NET, Mono Project (cid:134) Common Language Infrastructure (CLI) .NET Framework (Cont’d) (cid:134) Common Language Infrastructure (CLI) (cid:132) Microsoft's implementation of the CLI is called the Common Language Runtime (CLR) (cid:132) CLR primary components: (cid:134) Common Type System (CTS) (cid:132) Type definitions independent of any specific programming language (cid:134) Common Language Specification (CLS) (cid:134) Just-In-Time compiler (JIT) and Intermediate Language (IL) (cid:132) Language Independent (cid:132) Abstraction similar to Java’s Virtual Machine (cid:134) Virtual Execution System (VES) (cid:132) Memory management and garbage collection (cid:132) Exception handling .NET Framework (Cont’d) (cid:134) Documentation, examples, tips: (cid:132) Microsoft Developer Network (MSDN) (cid:132) Search Engines (cid:134) Google code search ( ) http://www.google.com/codesearch (cid:132) Programming websites and forums (cid:134) Most of the times your question has been answered before – needs patience and good search keywords!! (cid:132) Books, online tutorials, … OOP: A software construction paradigm (cid:134) Objects (cid:132) Abstract concepts, basic entities that describe internal information (variables) and the means to access it, change its state, perform actions (functions) (cid:132) In C# (like Java and most OOP languages) everything is an object (cid:134) Classes (cid:132) Programmer-defined types that model the parts of the system (objects) (cid:132) Basically a blueprint (cid:134) Instances (cid:132) Building blocks of the code (cid:132) Allocated in memory sharing the code but not the data (cid:134) Methods/Variables (cid:132) Primary mechanisms (code common to all instances of a class) and data variables (cid:132) Static parts: belong to a class, accessible and shared by all instances OOP (Cont’d) OOP (Cont’d) (cid:134) Abstraction (cid:134) Inheritance (cid:134) Polymorphism (cid:134) Encapsulation (cid:134) Simple example: … public class MyNumber { int val = 20; public int value() { return val; } public int increase(int how_much) { val += how_much; //val = val + how much; return val; } } … MyNumber m = new MyNumber(); int l = m.value(); // l will be 20 int k = m.increase(12); // k will be 32 C# Basics (cid:134) Case sensitive (cid:134) Common data types (primitives): (cid:132) bool, byte, short/int/long, float/double, char/string (cid:134) Conversion (cid:132) implicitly (cid:134) float f = 56; (cid:132) by casting (cid:134) int i = (int)5.6; (cid:132) with convert class (cid:134) int i = System.Convert.ToInt32(3.25d); (cid:132) provided methods (cid:134) string s = (5.25).ToString(); Type Casting (cid:134) Int ⇔ byte array (4 bytes) (cid:132) byte [] b = BitConverter.GetBytes(integer); (cid:132) int i = BitConverter.ToInt32(b, 0); (cid:134) float ⇔ byte array (4 bytes) (cid:132) byte[] b = BitConverter.GetBytes(float); (cid:132) float f = BitConverter.ToSingle(b, 0); (cid:134) String ⇔ byte array (cid:132) byte[] b = new ASCIIEncoding().GetBytes(string); (cid:132) string s = new ASCIIEncoding().GetString(b, 0, length);
Description: