Michael Olivero Microsoft Student Ambassador for FIU

Slides:



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

Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Arrays, A1 COMP 401, Fall 2014 Lecture 4 8/28/2014.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
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++
Constants. 2 Objectives Describe ways to create constants –const –readonly –enum.
Writing Object Oriented Software with C#. C# and OOP C# is designed for the.NET Framework  The.NET Framework is Object Oriented In C#  Your access to.
C# Programming: From Problem Analysis to Program Design1 Advanced Collections C# Programming: From Problem Analysis to Program Design 3 rd Edition 8.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Chapter 9: Advanced Array Concepts
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
C Tokens Identifiers Keywords Constants Operators Special symbols.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Arrays BCIS 3680 Enterprise Programming. Overview 2  Array terminology  Creating arrays  Declaring and instantiating an array  Assigning value to.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
5. Collections Arrays Other basic data structures.NET collections Class library example.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Understanding Data Types and Collections Lesson 2.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Enumeration.
CONTENTS Wrapper Class Enumeration Garbage Collection Import static.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Introduction to Object-Oriented Programming Lesson 2.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
Object Oriented Software Development 4. C# data types, objects and references.
1 9/22/05CS360 Windows Programming Arrays, Collections, Hash Tables, Strings.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
Array Declarations Arrays contain a fixed number of variables of identical type Array declaration and allocation are separate operations Declaration examples:
Introduction to C# By: Abir Ghattas Michel Barakat.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
Arrays & Enum & Events. Arrays Arrays are data structures consisting of related data items of the same type. Arrays are fixed-length entities—they remain.
Pointers A pointer type variable holds the address of a data object or a function. A pointer can refer to an object of any one data type; it cannot refer.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
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 –
Chapter  Array-like data structures  ArrayList  Queue  Stack  Hashtable  SortedList  Offer programming convenience for specific access.
Lecture 8: Collections, Comparisons and Conversions. Svetla Boytcheva AUBG, Spring COS 240 Object-Oriented Languages.
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
LESSON 06.
A variable is a name for a value stored in memory.
Basic Introduction to C#
Data Types, Arithmetic Operations
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Primitive Types Vs. Reference Types, Strings, Enumerations
.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
Java Basics Data Types in Java.
5. 3 Coding with Denotations
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Michael Olivero Microsoft Student Ambassador for FIU

Pre-Lecture Topics  Web site resources  Lecture & Materials   MSDN AA program 

Topics Covered Today  Using Data Types  Using Constants, Enums, Arrays, and Collections  Implementing Properties  Implementing Delegates & Events  Mobile Application Development  Give Away

Using Data Types After this lesson, you will be able to :  Describe the data types provided by the.NET Framework  Explain how to perform implicit and explicit conversions between types  Describe the functionality provided by types of the.NET Framework  Describe string manipulation functions with the String class methods

Data Types  All.NET languages are strongly typed  Built in Value Types  Integer Types  Floating-point Types  Boolean Type  Char Type  Built in Reference Types  String  Object

Data Types Mappings from.NET to C# & VB.NET TYPEC#VB.NETRANGE System.BytebyteByte 0 – 255 System.Int16shortShort – System.Int32intInteger to System.Int64longLong to System.SBytesbyte(NA) -128 to 127 System.UInt16ushort(NA) 0 to System.UInt32uint(NA) 0 to System.UInt64ulong(NA) 0 to

System.Object  The Object type is the supertype of all types in the.NET Framework.  Every type, whether value type or reference type, derives from System.Object.

Converting Types  Implicit Conversions  are performed whenever the conversion can occur without the loss (ex. long t = intValue; )  Explicit Conversion  Necessary when conversion where types cannot be implicitly converted  Cast similar to Java & C++  (ex. int t = (int)longValue; )  System.Convert class

Common Type Methods  Equals  Determines whether two instances are equal  GetHashCode  Serves as a hash function for a particular type  GetType  Returns the type object for the current instance  ToString  Returns a human-readable form of the object

ValueType.Parse()  All built in value types have a Parse() method.  The Parse method can be used to convert a string to the type desired.  Ex:  int Age = Int32.Parse( tbxAge.Text );  int Age = int.Parse( tbxAge.Text );

Common String methods  String.Replace()  Replaces all occurrences of a specified character in the string with another specified character  String.Split()  Returns an array of substrings that are delimited by a specified character  String.Substring()  Returns a substring from the specified instance  String.ToUpper(), ToLower()  Returns the string converted to all lowercase or all uppercase, respectively

Demo  System.Convert functions  Int.Parse()  Recommendation on StringBuilder

Topics Covered Today Using Data Types Using Data Types  Using Constants, Enums, Arrays, and Collections  Implementing Properties  Implementing Delegates & Events  Mobile Application Development  Give Away

Const, Enum, Array, Collections After this lesson, you will be able to :  Create constants and enumerations, and use them in methods  Describe how to create and use arrays  Explain what a collection is and how to use one  Describe how to enumerate through the members of a collection or an array

Why use Const & Enums  Constants  Can have user-friendly names to represent frequently used values  Syntax: public const double Pi = ;  Enumerations (enums)  Allow you to organize sets of related integral constants and use the sets to help make your application easy to read and debug.  Ex:  Enum Section { Name, Phone, Address };  SetValue( Section.Name, “Michael” ); vs.  SetValue( “Name”, “Michael” ); Could have typo’s

Enumerations  Allow you to work with sets of related constants and to associate easy-to-remember names with those sets.  Ex: public enum DaysOfWeek{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }  Can refer to constant with  DaysOfWeek.Monday

Enumerations (cont)  The default data type for enumerations is int  It can be any of the integral numeric data types  byte, short, int, and long  To define an enum as a different data type, you must specify it in the declaration line.  Ex: public enum DaysOfWeek : byte { … }  You can assign values; default starts at 0  Enum DaysOfWeek { Monday = 1, Tuesday = 2..}

Demo  Enum  Enum ToString()

Array Basics  Arrays are a way to manage groups of similarly typed values or objects  Similar to Java  Declaration Syntax:  int[ ] MyNumbers = new int[ 5 ];  string[ ] MyStrings = new string[ 5 ];  Inline Initialization Syntax:  Int[ ] MyNumbers = new int[ ] { 4, 3, 2 };

Multidimensional Arrays.NET Framework supports two forms of multidimensional arrays  Jagged Arrays  Array of Arrays (as in Java)  Rectangular Arrays  Length are the same for same dimension

Multidimensional Arrays (cont)  Jagged Arrays  Syntax: string[ ][ ] Families = new string[2] [ ]; Families[0] = new string[ 4 ] ; //array of 4 Families[1] = new string[ 2 ]; //array of 2

Multidimensional Arrays (cont)  Rectangular Arrays  Syntax: string[, ] stringArrays = new string[5, 3];  Think of as a table with rows and columns.

Collections  Namespace: System.Collections  Ex. ArrayList  Provides same functionality as arrays with additional benefits.  Auto resizing  Internal collection type is Object

ArrayList Collection ( cont )  Typical Methods / Properties  Add( object )  To add an object to the collection  Remove( object )  To remove the object in the collection with the same reference  RemoveAt( int index )  To remove the object in the collection with the corresponding index.  Count  Total number of element stored in the collection

Some other collections ClassDescription BitArray Manages a compact array of bits (1 and 0) Hashtable Represents a collection of key-and-value pairs that are organized base on the hash code of the key Queue Manages a group of objects on a first-in, first-out basis SortedList Organizes a group of objects and allows you to access those objects either by index or by a key value. Stack Manages a grou of objects on a first-in, last-out basis

Iteration over a collection  foreach keyword  Can be used to iterate over the values in a collection  Syntax: int [ ] MyIntegers = new int[ ] { 1, 2, 3, 4, 5 }; foreach( int i in MyIntegers ) { MessageBox.Show( i.ToString() ); }

Topics Covered Today Using Data Types Using Data Types Using Constants, Enums, Arrays, and Collections Using Constants, Enums, Arrays, and Collections  Implementing Properties  Implementing Delegates & Events  Mobile Application Development  Give Away

Properties After this lesson, you will be able to:  Explain how to implement properties  Describe how to create a read-only or write-only property

Properties  What are they?  Properties are a specialized methods that look like a field. Their values are set and retrieved similar to fields.  Why use properties?  Simplicity  Extensive use in DataBinding (future lecture)

Properties (cont)  Typically used to expose a private or protected field; similar to a method.  Property can be used to set the value of a field or retrieve a value of a field.  Key advantage, can scrutinize value being assigned prior to assigning it.

Properties - Syntax public String FirstName { get//reading { return m_FirstName; } set//writing { m_FirstName = value; }}  Value keyword is special; it is the value being passed in to the property.

Properties – Additional Info  Some additional topics of significance to look into  Creating an Indexer property  Creating a Collection property

Demo  Properties

Topics Covered Today Using Data Types Using Data Types Using Constants, Enums, Arrays, and Collections Using Constants, Enums, Arrays, and Collections Implementing Properties Implementing Properties  Implementing Delegates & Events  Mobile Application Development  Give Away

Delegates And Events After this lesson you will be able to:  Explain what a delegate is and how to create one  Describe how to declare and raise events from your application  Explain how to implement event handlers and associate them with events  Describe how to dynamically add and remove event handlers at run time

Delegates  Are essential and central to how events work in.NET  In essence, a delegate is a function pointer that is also type safe.

How to use a delegate 4 Steps 1. Declare the delegate type variable specifying the prototype signature of the methods it is allowed to call. 2. Create a method that matches the signature of the delegate. 3. Create an new instance of that delegate type passing it the method name from #2 4. Invoke the function through the delegate as many times as necessary.

How to Declare a Delegate  [ qualifier ] delegate [ function prototype signature ]  Ex: public delegate int DoubleDelegate( int a ); Signature of Delegate The type name of your delegate

Create a method to match public delegate int DoubleDelegate( int a); … int DoubleNumber( int aNumber ) { return aNumber * 2; }

Create an instance of delegate public delegate int DoubleDelegate( int a); … int DoubleNumber( int aNumber ) { return aNumber * 2; } DoubleDelegate myDelegate = new DoubleDelegate( DoubleNumber );

Call the delegate as you wish public delegate int DoubleDelegate( int a); … int DoubleNumber( int aNumber ) { return aNumber * 2; } DoubleDelegate myDelegate = new DoubleDelegate( DoubleNumber ); int total = myDelegate( 100 );//total = 200 int total2 = myDelegate( 15 ); //total2 = 30

Events  Events are tied to delegates. When an event is declared, the corresponding delegate is specified.  In C#, once an event is declared, it must be associated with one or more event handlers before it can be raised. An event handler is a method that is called through a delegate when an event is raised.  The function prototype used to handle the event is the same prototype as the delegate associated with the event.

Events Syntax public delegate void calculationDelegate(double d);public event calculationDelegate CalculationComplete; CalculationComplete( 44.4 );//raises the event The delegate type The event Reference variable

Event Handlers  Once an event is declared, it must be associated with one or more event handlers before it can be raised.  Creating an event handler is as simple as  Defining a method that matches the signature of the delegate corresponding to the event.  creating an instance of a Delegate passing the function name that will handle the event and registering it with the event. Ex: myEvent += new DoubleDelegate( DblFunc );

Event Handlers in Forms  Events in Forms are handled by the delegate System.EventHandler  Example: Button1.OnClick += new System.EventHandler(OnClick); Instance of a Button object Event object In Button class To Handle Clicks The delegate that handles Most form events. Delegate Is located in the System namespace. The method on the Form that will handle The event.

Topics Covered Today Using Data Types Using Data Types Using Constants, Enums, Arrays, and Collections Using Constants, Enums, Arrays, and Collections Implementing Properties Implementing Properties Implementing Delegates & Events Implementing Delegates & Events  Mobile Application Development  Give Away