Module 6: Building .NET–based Applications with C#

Slides:



Advertisements
Similar presentations
Advanced.Net Framework 2.0 David Ringsell MCPD MCSD MCT MCAD.
Advertisements

Reading and Writing Text Files Svetlin Nakov Telerik Corporation
Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
Introduction to the C# Programming Language for the VB Programmer.
File Systems Files and directories Absolute and relative names Text and binary files Sequential-access and random-access files.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
C# Programming: From Problem Analysis to Program Design1 Working with Files C# Programming: From Problem Analysis to Program Design 3 rd Edition 13.
File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Understanding Input/Output (I/O) Classes Lesson 5.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Computer and Programming File I/O File Input/Output Author: Chaiporn Jaikaeo, Jittat Fakcharoenphol Edited by Supaporn Erjongmanee Lecture 13.
Lecture Set 12 Sequential Files and Structures Part B – Reading and Writing Sequential Files.
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
Chapter 12 Working with Files CIS 3260 Introduction to Programming using C# Hiro Takeda.
Neal Stublen Open/Close Connections  ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Serialization  What is Serialization?  System.Serialization  Scenarios in Serialization  Basic Serialization  Custom Serialization.
Methods Session 04 Mata kuliah: M0874 – Programming II Tahun: 2010.
Streams & File Input/Output Basics C#.Net Development Version 1.1.
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
Files and Streams File Types, Using Streams, Manipulating Files SoftUni Team Technical Trainers Software University
Homework #5 New York University Computer Science Department Data Structures Fall 2008 Eugene Weinstein.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
Object Oriented Software Development 10. Persistent Storage.
Chapter 2 Part C – More on the Help System and The Object Browser (scan quickly for future reference)
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
CS360 Windows Programming
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
BIM313 – Advanced Programming File Operations 1. Contents Structure of a File Reading/Writing Texts from/to Files File and Directory Operations 2.
Chapter 8 Files 1/4/20161Copyright © 2012 Thomas P. Skinner.
Text Files and String Processing
Input and Output 23: Input and Output
CSC 298 Streams and files.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
Ajay Tripathi Input Output. Ajay Tripathi Input/output (IO) refers to the operations for reading and writing data to streams and files. In the.NET Framework,
Files and Streams. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a permanent way to store.
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
Strings in C++/CLI us/library/system.string.aspxhttp://msdn.microsoft.com/en- us/library/system.string.aspx public: static.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
VB.Net. Topics Introduction to VB.Net Creating VB.Net Project in VS 2005 Data types and Operators in VB.Net String Functions Conditions (If Else, Select.
Chapter 6: Creating Windows–based Applications 1 Microsoft® Visual C# 2008.
C# / ASP.NET 教育訓練. 講師: 梁國亮 Emai: 認證 Microsoft Certified Trainer Microsoft Certified CE 5.0 / 6.0 / XP Embedded Trainer Microsoft SBS-MVP.
INF230 Basics in C# Programming
Creating and Using Objects, Exceptions, Strings
Input and Output 23: Input and Output
C# Programming: From Problem Analysis to Program Design
Module 5: Common Type System
Defiana Arnaldy, M.Si File and Stream I/O Defiana Arnaldy, M.Si
File Types, Using Streams, Manipulating Files
How to work with files and data streams
Files and Streams.
C# Programming: From Problem Analysis to Program Design
Chapter 3 The .NET Framework Class Library (FCL)
Files and Streams Lect3 CT1411.
Sequential Input and Output using Text Files
File Input/Output (I/O)
Object Oriented Programming (OOP) LAB # 8
טיפול בקבצים ליווי מקצועי : ארז קלר
Module 2: Understanding C# Language Fundamentals
Files & Streams.
Files and Streams Lect10 GC201 12/1/2015.
Fundaments of Game Design
How to work with files and data streams
NAMESPACE.
Files and Streams.
Presentation transcript:

Module 6: Building .NET–based Applications with C#

Overview Examining the .NET Framework Class Library Overriding Methods from System.Object Formatting Strings and Numbers Using Streams and Files

Lesson: Examining the .NET Framework Class Library The Object Browser

.NET Framework Class Library System System.Collections System.Diagnostics System.IO System.Data System.Drawing System.Windows.Forms System.Web.Services System.Web.UI Classes in the .NET Framework class library are arranged into a hierarchy of namespaces Most common namespaces

The Object Browser Allows you to examine and discover objects and their members Objects pane Members pane Description pane Browse Customize Toolbar

Practice: Using the Object Browser Hands-on Practice In this practice, you will open Object Browser, navigate namespaces and members, and document your results 10 min

Lesson: Overriding Methods from System.Object Methods Inherited from System.Object How to Override and Implement ToString

Methods Inherited from System.Object ToString Creates and returns a human-readable text string that describes an instance of the class GetHashCode Returns an integer number as a hashcode for the object Equals Determines whether two objects are equal GetType Returns the type of the current instance

How to Override and Implement ToString Inherited ToString() returns the name of the class public enum CarSize { Large, Medium, Small, } public class Car { public CarType Size; public int TopSpeed; Car myCar = new Car(); myCar.Size = CarSize.Small; MessageBox.Show(myCar.ToString()); WindowsApplication1.Form1.Car Override ToString to provide a more useful string public override string ToString() { return ( this.Size.ToString() + " Car"); } Small Car

Practice: Overriding the ToString Method Hands-on Practice In this practice, you will override the ToString method 10 min

Lesson: Formatting Strings and Numbers How to Format Numbers How to Format Date and Time How to Create Dynamic Strings

How to Format Numbers Some .NET Framework classes use format strings to return common numeric string types, including these methods: String.Format, ToString, Console.WriteLine String.Format class example The {0:c} is the formatting information, where "0" is the index of the following objects ":c" dictates that the output use the currency format Output is $12,345.67 (on a US English computer) Custom numeric format strings apply to any format string that does not fit the definition of a standard numeric format string # character in the number example string s = String.Format( "{0:c}", 12345.67 );

How to Format Date and Time DateTimeFormatInfo class Used for formatting DateTime objects String output is: Wednesday, March 20, 2002 10:30 AM Custom formatting string String output is: 20 Mar 2002 - 10:30:00 System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("f")); System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("dd MMM yyyy - hh:mm:ss"));

How to Create Dynamic Strings Question: After executing the following code, how can you preserve computer memory? Solution: Use the StringBuilder Class for (int i=0; i < 1000; i++) { s = s.Concat(s, i.ToString()); } StringBuilder s = new StringBuilder(); for (int i=0; i < 1000; i++) { s.Append(i); }

Practice: Formatting Strings Hands-on Practice In this practice, you will provide the correct formatting code that produces the required output to a series of formatting questions provided in a C# application 10 min

Lesson: Using Streams and Files What Is File I/O? How to Read and Write Text Files How to Read and Write Binary Files How to Traverse the Windows File System

What Is File I/O? A file is a collection of data stored on a disk with a name and often a directory path A stream is something on which you can perform read and write operations FileAccess Enumerations Read, ReadWrite, Write FileShare Enumerations Inheritable, None, Read, ReadWrite, Write FileMode Enumerations Append, Create, CreateNew, Open, OpenOrCreate, Truncate

How to Read and Write Text Files Class Example StreamReader StreamReader sr = new StreamReader(@"C:\SETUP.LOG"); textBox1.Text = sr.ReadToEnd(); sr.Close(); StreamWriter StreamWriter sw = new StreamWriter(@"C:\TEST.LOG",false); sw.WriteLine("Log Line 1"); sw.WriteLine("Log Line 2"); sr.Close(); XmlTextReader public class XmlTextReader : XmlReader, IXmlLineInfo XmlTextWriter w.WriteStartElement("root"); w.WriteAttributeString("xmlns", "x", null, "urn:1"); w.WriteStartElement("item","urn:1"); w.WriteEndElement(); w.WriteEndElement();

How to Read and Write Binary Files BinaryReader Reads primitive data types as binary values in a specific encoding BinaryWriter Writes primitive types in binary to a stream and supports writing strings in a specific encoding FileStream fs = new FileStream(@"C:\TEST2.DAT",FileMode.CreateNew); BinaryWriter w = new BinaryWriter(fs); w.Write((byte)65); w.Write((byte)66); w.Close(); fs.Close();

How to Traverse the Windows File System Using the DirectoryInfo and FileInfo classes Using recursion Technique where a function calls itself, repeatedly, passing in a different parameter DirectoryInfo d = new DirectoryInfo("C:\\"); DirectoryInfo[] subd = d.GetDirectories(); foreach (DirectoryInfo dd in subd) { if (dd.Attributes==FileAttributes.Directory) { FileInfo[] f = dd.GetFiles(); foreach (FileInfo fi in f) { listBox1.Items.Add(fi.ToString()); }

Practice: Using File System Information Guided Practice In this practice, you will create a Windows- based application that calculates the size of all the files that are contained in a folder 10 min

Review Examining the .NET Framework Class Library Overriding Methods from System.Object Formatting Strings and Numbers Using Streams and Files

Lab 6.1: Using Streams Exercise 1: Converting a Binary File to a Text File 1 hour