Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Road Map Introduction to object oriented programming. Classes
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Introduction to the C# Programming Language for the VB Programmer.
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
Terms and Rules Professor Evan Korth New York University (All rights reserved)
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ASP.NET Programming with C# and SQL Server First Edition
Intro to C# Language Richard Della Tezra IS 373. What Is C#? C# is type-safe object-oriented language Enables developers to build a variety of secure.
Abstract Data Types and Encapsulation Concepts
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Programming in C# Language Overview
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
OOP Languages: Java vs C++
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Module 1: Introduction to C# Module 2: Variables and Data Types
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Introduction to .NET Framework
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
The Java Programming Language
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
C#C# Introduction CS3260 Dennis A. Fairclough Version 1.0 Introduction CS3260 Dennis A. Fairclough Version 1.0.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Object Oriented Software Development
Understanding Data Types and Collections Lesson 2.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Object-Oriented Programming Chapter Chapter
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Introduction to Object-Oriented Programming Lesson 2.
Object Oriented Software Development 4. C# data types, objects and references.
Session 1 C# Basics.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
C# Diline Giriş.
Creating and Using Objects, Exceptions, Strings
Ch 10- Advanced Object-Oriented Programming Features
Java Primer 1: Types, Classes and Operators
Module 5: Common Type System
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
CS360 Windows Programming
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Java Programming Language
IS 135 Business Programming
Presentation transcript:

Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications which can be built using C# include traditional Windows client applications, XML web services, distributed components, client-server applications, database applications, and much more. - Visual C# 2010 provides an advanced code editor, convenient user interface designers, integrated debugger based on version 4.0 of C# language, and version 4.0 of.NET Framework.

Introduction to C# - II C# syntax is highly expressive, yet easy and simple to learn. Familiarity with Java, C, C++ → familiarity with C# C# syntax simplifies many of the complexities of C++ C# provides powerful features such as nullable value types, enumerations, delegates, lambda expressions and direct memory access, which are not found in Java

Introduction to C# - III C# supports generic methods and types, which provide increased type safety and performance Language-Integrated Query (LINQ) expressions make the strongly-typed query a first-class language construct C# supports encapsulation, inheritance, and polymorphism C# class may inherit from only one class, however implement more than one interface.

Introduction to C# - IV Struct in C# - stack-allocated type, can implement interfaces, not support inheritance Innovative software constructs in C# include: Delegates – encapsulated method signatures Properties – accessors for private member variables Attributes - provide declarative metadata about types at run time Inline XML documentation comments Language-Integrated Query (LINQ)

Introduction to C# - V Interop – allows C# programs to use native C++ code, including pointers, and “unsafe” code C# got simple build process compared to C and C++ and more flexible than in Java. no separate header files. no requirement that methods and types be declared in a particular order. A C# source file may define any number of classes, structs, interfaces, and events.

Structure of a C# program // A Hello World! program in C#. using System; namespace HelloWorld { class Hello { static void Main() { Console.WriteLine("Hello World!"); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }

Structure of a C# program - II Comments: //single line comments /*a block of comments*/ Main method: Where control starts and ends Can take arguments (string []) and can return void or int. Compiling & Executing: “csc Hello.cs”->Hello.exe, then “Hello.exe” on command prompt

Structure of a C# program - III // A skeleton of a C# program using System; namespace YourNamespace { class YourClass { } struct YourStruct { } interface IYourInterface { } delegate int YourDelegate(); enum YourEnum { }

Structure of a C# program - IV namespace YourNestedNamespace { struct YourStruct { } } class YourMainClass { static void Main(string[] args) { //Your program starts here... }

Structure of a C# program - V On start of application, Main method the first method to be invoked. Can only be one entry point in a C# program. Main must be static, and it should not be public. Parameters are read as zero-indexed command-line arguments. Unlike C and C++, the name of the program is not treated as the first command-line argument.

Structure of a C# program - VI class CommandLine2 { static void Main(string[] args) { System.Console.WriteLine("Number of command line parameters = {0}", args.Length); foreach (string s in args) { System.Console.WriteLine(s); }

Structure of a C# program - VII /* Output: Number of command line parameters = 3 Muhammad Eesa Musa */

Structure of a C# program - VIII To compile the code from a command prompt, use the Visual Studio Command Prompt, available from the Start menu under Visual Studio Tools.

Types C# is a strongly-typed language. Every variable and constant has a type, as does every expression that evaluates to a value. Every method signature specifies a type for each input parameter and for the return value. The.NET Framework class library defines a set of built-in numeric types as well as more complex types that represent a wide variety of logical constructs, such as the file system, network connections, collections and arrays of objects, and dates.

Types – II information stored in a type includes The storage space that a variable of the type requires. The maximum and minimum values that it can represent The base type it inherits from. The location where the memory for variables will be allocated at run time. The kinds of operations that are permitted.

Types - III Compiler uses information stored in the type to ensure type safety. The compiler embeds the type information into the executable file as metadata. The common language runtime (CLR) uses that metadata at run time to further guarantee type safety when it allocates and reclaims memory. Type of a variable or constant must be declared, or use var keyword to let the compiler infer its type.

Types - IV After a variable is declared, it cannot be re- declared with a new type, and it cannot be assigned a value that is not compatible with its declared type. Types can be converted to other types. A conversion in which there is no data loss is done automatically by the compiler. A conversion in which there is data loss requires explicit cast.

Types - V C# provides a standard set of built-in numeric types to represent integers, floating point values, Boolean expressions, text characters, decimal values, and other types of data. There are also built-in string and object types. struct, class, interface, and enum constructs can be used to create custom types.

Types - VI Common Type System supports the principle of inheritance Types can derive from other types, called base types. The derived type inherits (with some restrictions) the methods, properties, and other members of the base type. All types derive ultimately from a single base type (System.Object (C# keyword: object)). This unified type hierarchy is called the Common Type System (CTS).

Types - VII Each type in the CTS is defined as either a value type or a reference type. Types that you define by using the struct keyword are value types; all the built-in numeric types are structs. Types that you define by using the class keyword are reference types. Reference types and value types have different compile-time rules, and different run-time behavior.

Types - VIII Value Types: Value types derive from System.ValueType, which derives from System.Object. Types that derive from System.ValueType have special behavior in the CLR. Value type variables directly contain their values, which means that the memory is allocated inline in whatever context the variable is declared. There is no separate heap allocation or garbage collection overhead for value-type variables.

Types - IX Categories of Value types:  Struct  Enum The built-in numeric types are structs. Value types are sealed, which means, for example, that you cannot derive a type from System.Int32, and you cannot define a struct to inherit from any user-defined class or struct because a struct can only inherit from System.ValueType. However, a struct can implement one or more interfaces.

Types - X You can cast a struct type to an interface type; this causes a boxing operation to wrap the struct inside a reference type object on the managed heap. Boxing operations occur when you pass a value type to a method that takes a System.Object as an input parameter. All enums inherit from System.Enum, which inherits from System.ValueType. All the rules that apply to structs also apply to enums. Reference Types: A type that is defined as a class, delegate, array, or interface is a reference type.

Types - XI When the object is created, the memory is allocated on the managed heap, and the variable holds only a reference to the location of the object. Reference types fully support inheritance. Generic Types: A type can be declared with one or more type parameters that serve as a placeholder for the actual type (the concrete type) that client code will provide when it creates an instance of the type. Such types are called generic types.

Types - XII e.g. the.NET Framework type System.Collections.Generic.List(Of T) has one type parameter. List strings = new List (); The use of the type parameter makes it possible to reuse the same class to hold any type of element, without having to convert each element to object. Generic collection classes are called strongly-typed collections because the compiler knows the specific type of the collection's elements. Implicit Types

Types - XIII you can implicitly type a local variable (but not class members) by using the var keyword. The variable still receives a type at compile time, but the type is provided by the compiler. Anonymous types: In some cases, it is inconvenient to create a named type for simple sets of related values that you do not intend to store or pass outside method boundaries. You can create anonymous types for this purpose. var v = new { Amount = 108, Message = "Hello" };

Types - XIV Nullable types: Ordinary value types cannot have a value of null. However, you can create nullable value types by affixing a ? after the type. In the CTS, nullable types are instances of the generic struct type System.Nullable(Of T).

References Visual Studio 2010 help