SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Object-Oriented Programming Using C#
Objectives


                In this session, you will learn to:
                   Implement read and write in text files
                   Implement read and write in binary files
                   Implement the Windows File System
                   Describe exceptions




     Ver. 1.0                        Session 13               Slide 1 of 24
Object-Oriented Programming Using C#
Implementing Reading and Writing in the Text Files


                • The Stream class is used to read from and to write data in
                  the text files.
                • It is an abstract class, which supports reading and writing
                  bytes into it.
                • If data of a file is only text, then you can use the
                  StreamReader class and the StreamWriter class to
                  accomplish the reading and writing tasks, respectively.




     Ver. 1.0                         Session 13                       Slide 2 of 24
Object-Oriented Programming Using C#
StreamReader Class


               • The StreamReader class is inherited from the abstract class
                 TextReader.
               • The TextReader class represents a reader which can read
                 a series of characters.




    Ver. 1.0                        Session 13                       Slide 3 of 24
Object-Oriented Programming Using C#
StreamReader Class (Contd.)


                • The following table describes some of the commonly used
                  methods of the StreamReader class.
                   Methods    Description
                   Close      Closes the object of StreamReader class and the underlying stream, and
                              releases any system resources associated with the reader
                   Peek       Returns the next available character but does not consume it
                   Read       Reads the next character or the next set of characters from the stream


                   ReadLine   Reads a line of characters from the current stream and returns data as a
                              string

                   Seek       Allows the read/write position to be moved to any position within the file




     Ver. 1.0                                Session 13                                                    Slide 4 of 24
Object-Oriented Programming Using C#
StreamWriter Class


                • The StreamWriter class is inherited from the abstract class
                  TextWriter.
                • The TextWriter class represents a writer, which can write
                  a series of characters.
                • The following table describes some of the commonly used
                  methods of the StreamWriter class.
                     Methods     Description

                     Close       Closes the current StreamWriter object and the underlying stream


                     Flush       Clears all buffers for the current writer and causes any buffered data to be
                                 written to the underlying stream

                     Write       Writes to the stream

                     WriteLine   Writes data specified by the overloaded parameters, followed by end of
                                 line




     Ver. 1.0                               Session 13                                                     Slide 5 of 24
Object-Oriented Programming Using C#
Implementing Reading and Writing in Binary Files


                • In C#, you can directly display the contents of the file on the
                  screen.
                • Binary read and write means that a number is written as a
                  float representation consuming four bytes of space.
                • The BinaryReader and BinaryWriter classes are used
                  for reading and writing the binary data in to files.




     Ver. 1.0                          Session 13                         Slide 6 of 24
Object-Oriented Programming Using C#
BinaryReader Class


                • The BinaryReader class is used to read binary data from
                  a file.
                • The following table describes some of the commonly used
                  methods of the BinaryReader class.

                       Method   Description
                       Close    Closes the current reader and the underlying stream
                       Read     Reads characters from the underlying stream and advances the current
                                position of the stream




     Ver. 1.0                             Session 13                                                   Slide 7 of 24
Object-Oriented Programming Using C#
BinaryWriter Class


                • The BinaryWriter class is used to write binary data to a
                  stream.
                • The following table describes some of the commonly used
                  methods of the BinaryWriter class.

                   Method    Description

                   Close     Closes the current BinaryWriter and the underlying stream

                   Seek      Sets the position within the current stream

                   Write     Writes a value to the current stream

                   Flush     Clears all buffers for the current writer and causes any buffered data
                             to be written to the underlying device




     Ver. 1.0                               Session 13                                                Slide 8 of 24
Object-Oriented Programming Using C#
Implementing the Windows File System


                • The ability to browse and locate files and directories for a
                  specific directory is essential for many programming tasks.
                • Using classes such as the DirectoryInfo and FileInfo
                  classes in combination is an efficient way to gather the
                  required information about files and directories in a specific
                  location.




     Ver. 1.0                         Session 13                        Slide 9 of 24
Object-Oriented Programming Using C#
DirectoryInfo Class


                • The DirectoryInfo class is derived from the
                  FileSystemInfo class.
                • The following table describes some of the commonly used
                  properties of the DirectoryInfo class.
                 Property         Description
                                  Gets or sets attributes associated with the current file. This property is inherited
                 Attributes
                                  from FileSystemInfo.
                                  Gets or sets CreationTime of the current file. This property is inherited from
                 CreationTime
                                  FileSystemInfo.
                 Exists           Gets a Boolean value indicating whether the directory exist or not.
                                  Gets a string containing the file extension. This property is inherited from
                 Extension
                                  FileSystemInfo.
                                  Gets a string containing the full path of the directory. This property is inherited from
                 FullName
                                  FileSystemInfo.
                                  Gets the last accessed time of the directory. This property is inherited from
                 LastAccessTime
                                  FileSystemInfo.
                 Name             Gets a string containing the name of a given file.




     Ver. 1.0                                 Session 13                                                      Slide 10 of 24
Object-Oriented Programming Using C#
DirectoryInfo Class (Contd.)


                • The following table describes some of the commonly used
                  methods of the DirectoryInfo class.
                   Method               Description
                   Create               Creates a directory.
                   CreateSubdirectory   Creates a subdirectory.
                   Delete               Deletes a directory.
                                        Returns the directories in the current directory after matching all the
                   GetDirectories
                                        criteria. It also allows you to search subdirectories within directories.
                   GetFiles             Returns the files in the current directory.




     Ver. 1.0                               Session 13                                                       Slide 11 of 24
Object-Oriented Programming Using C#
FileInfo Class


                • The FileInfo class is derived from FileSystemInfo
                  class.
                • The following table describes some commonly used
                  properties FileInfo class.
                   Property         Description
                                    Gets or sets attributes associated with the current file. This property is inherited from
                   Attributes
                                    FileSystemInfo.
                                    Gets or sets CreationTime of the current file. This property is inherited from
                   CreationTime
                                    FileSystemInfo.
                   Directory        Gets an instance of the directory which the file belongs to.
                   Exists           Gets a boolean value indicating whether the file exists or not.
                   Extension        Gets a string containing the file extension. This property is inherited from FileSystemInfo.
                                    Gets a string containing the full path of the file. This property is inherited from
                   FullName
                                    FileSystemInfo.
                   LastAccessTime   Gets the last accessed time of the file. This property is inherited from FileSystemInfo.
                                    Gets the time of the last written activity to the file. This property is inherited from
                   LastWriteTime
                                    FileSystemInfo.
                   Length           Gets the size of the file.
                   Name             Gets a string containing the name of a given file.


     Ver. 1.0                                      Session 13                                                                 Slide 12 of 24
Object-Oriented Programming Using C#
FileInfo Class (Contd.)


                • The following table describes some of the commonly used
                  methods of the FileInfo class.
                 Method       Description
                 Create       Creates a file
                 AppendText   Appends a text to the file represented by the FileInfo object
                 Delete       Deletes a file
                 Open         Opens file
                 OpenRead     Opens a file in read-only mode




     Ver. 1.0                              Session 13                                         Slide 13 of 24
Object-Oriented Programming Using C#
Describing Exceptions


                An exception is an erroneous situation that occurs during
                program execution.
                When an exception occurs in an application, the system
                throws an error.
                The error is handled through the process of exception
                handling.




     Ver. 1.0                      Session 13                       Slide 14 of 24
Object-Oriented Programming Using C#
Types of Errors


                There are three types of errors that can occur in the
                application:
                 – Syntax errors: Occurs when statements are not constructed
                   properly, keywords are misspelled, or punctuation is omitted.
                 – Run-time errors: Occurs when an application attempts to
                   perform an operation, which is not allowed at runtime.
                 – Logical errors: Occurs when an application compiles and runs
                   properly but does not produce the expected results.


                Let us understand the various types of errors in detail.




     Ver. 1.0                       Session 13                          Slide 15 of 24
Object-Oriented Programming Using C#
Syntax Errors


                      class Errors
                      {

                          Console.WriteLine(“Enjoy Errors”)

                      }




                Semicolon is missing from Console.WriteLine statement




     Ver. 1.0                     Session 13                     Slide 16 of 24
Object-Oriented Programming Using C#
Run-Time Errors


                           class Errors

                            {
                                 int Num1=0;
                                 int Num2=20;
                                 int Num3;
                                 Num3=Num2/Num1;


                                 Console.WriteLine(“The Result is {0}”,
                                 Num3);
                             }


                Division by zero has taken place



     Ver. 1.0                           Session 13                 Slide 17 of 24
Object-Oriented Programming Using C#
Logical Errors


                            class Errors
                             {
                                 int Num1=10;
                                 int Num2=2;
                                 int Num3;
                              Num3=Num2/Num1;


                                 Console.WriteLine(“The Result is
                                 {0}”, Num3);
                             }
                Expected result = 5

                Present result = 0.2



     Ver. 1.0                           Session 13                  Slide 18 of 24
Object-Oriented Programming Using C#
Exception Classes


                • There are many exception classes which are directly or
                  indirectly derived from the System.Exception class.
                  Some of these classes are:
                   – System.ApplicationException class
                   – System.SystemException class




     Ver. 1.0                        Session 13                      Slide 19 of 24
Object-Oriented Programming Using C#
Exception Classes (Contd.)


                The hierarchy of the exception classes is displayed in the
                following figure.

                          System.Exception




                                                 System.ApplicationException




                                                   System.SystemException




     Ver. 1.0                                Session 13                        Slide 20 of 24
Object-Oriented Programming Using C#
Exception Classes (Contd.)


                • The System.SystemException acts as a base class for
                  all the predefined system exceptions. The following table
                  describes some of the classes derived from the
                  System.SystemException class.
                Exception Classes                   Description

                System.IO.IOException               Handles I/O errors

                System.IndexOutOfRangeException     Handles errors generated when a method refers to an array
                                                    element, which is out of its bound
                System.NullReferenceException       Handles errors generated during the process of
                                                    dereferencing a null object
                System.DivideByZeroException        Handles errors generated during the process of dividing the
                                                    dividend with zero
                System.InvalidCastException         Handles errors generated during typecasting
                System.OutOfMemoryException         Handles memory allocation to the application errors




     Ver. 1.0                                     Session 13                                                Slide 21 of 24
Object-Oriented Programming Using C#
Summary


               In this session, you learned that:
                – The Stream class is used to read and write data to the text
                  files. It is an abstract class, which supports reading and writing
                  bytes into it.
                – The StreamReader class is inherited from the abstract class
                  TextReader. The TextReader class represents a reader
                  which can read a series of characters.
                – The StreamWriter class is inherited from the abstract class
                  TextWriter. The TextWriter class represents a writer,
                  which can write a series of characters.
                – The BinaryReader class allows reading of binary data from a
                  file.
                – The BinaryWriter class allows writing of binary data to a
                  stream.



    Ver. 1.0                         Session 13                            Slide 22 of 24
Object-Oriented Programming Using C#
Summary (Contd.)


               – The DirectoryInfo class is derived from FileSystemInfo
                 class and it works on a specific directory and shows the
                 fullpath of the current directory.
               – The FileInfo class is derived from FileSystemInfo class
                 and it works on a specific directory to display the list of all the
                 files.
               – An exception is an erroneous situation that occurs during
                 program execution.
               – A syntax error occurs when a compiler cannot compile the
                 code. This may happen when the statements are not
                 constructed properly, keywords are misspelled, or punctuation
                 is omitted.
               – A run-time error occurs when an application attempts to
                 perform an operation that is not allowed.



    Ver. 1.0                        Session 13                             Slide 23 of 24
Object-Oriented Programming Using C#
Summary (Contd.)


               A logical error occurs when an application compiles and runs
               properly but does not produce the expected results.
               Exceptional conditions arise when an operation cannot be
               completed normally during the processing of C# statements
               and expressions.




    Ver. 1.0                    Session 13                           Slide 24 of 24

Weitere ähnliche Inhalte

Was ist angesagt?

01 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_0101 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_01
Niit Care
 
03 iec t1_s1_oo_ps_session_04
03 iec t1_s1_oo_ps_session_0403 iec t1_s1_oo_ps_session_04
03 iec t1_s1_oo_ps_session_04
Niit Care
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
Niit Care
 
Java session02
Java session02Java session02
Java session02
Niit Care
 
Java session01
Java session01Java session01
Java session01
Niit Care
 
C programming session 14
C programming session 14C programming session 14
C programming session 14
AjayBahoriya
 

Was ist angesagt? (20)

01 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_0101 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_01
 
03 iec t1_s1_oo_ps_session_04
03 iec t1_s1_oo_ps_session_0403 iec t1_s1_oo_ps_session_04
03 iec t1_s1_oo_ps_session_04
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
 
01 gui 01
01 gui 0101 gui 01
01 gui 01
 
Java session02
Java session02Java session02
Java session02
 
Java session01
Java session01Java session01
Java session01
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 
Csharp
CsharpCsharp
Csharp
 
Win32/Flamer: Reverse Engineering and Framework Reconstruction
Win32/Flamer: Reverse Engineering and Framework ReconstructionWin32/Flamer: Reverse Engineering and Framework Reconstruction
Win32/Flamer: Reverse Engineering and Framework Reconstruction
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
C programming session 14
C programming session 14C programming session 14
C programming session 14
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 
Tutorial c#
Tutorial c#Tutorial c#
Tutorial c#
 
NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)
 
02 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_0202 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_02
 
Dacj 1-2 a
Dacj 1-2 aDacj 1-2 a
Dacj 1-2 a
 
Dot net introduction
Dot net introductionDot net introduction
Dot net introduction
 
Session2 (3)
Session2 (3)Session2 (3)
Session2 (3)
 
C# Unit 2 notes
C# Unit 2 notesC# Unit 2 notes
C# Unit 2 notes
 
.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti
 

Andere mochten auch

Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09
Niit Care
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16
Niit Care
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20
Niit Care
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01
Niit Care
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19
Niit Care
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_c
Niit Care
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
Niit Care
 

Andere mochten auch (20)

 
Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20
 
Dacj 2-2 c
Dacj 2-2 cDacj 2-2 c
Dacj 2-2 c
 
Oops recap
Oops recapOops recap
Oops recap
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Rdbms xp 01
Rdbms xp 01Rdbms xp 01
Rdbms xp 01
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_c
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Ds 8
Ds 8Ds 8
Ds 8
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About It
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
 
Dacj 1-1 a
Dacj 1-1 aDacj 1-1 a
Dacj 1-1 a
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Chapter 21 c language
Chapter 21 c languageChapter 21 c language
Chapter 21 c language
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 

Ähnlich wie 09 iec t1_s1_oo_ps_session_13

ASP.NET Session 7
ASP.NET Session 7ASP.NET Session 7
ASP.NET Session 7
Sisir Ghosh
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
myrajendra
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
myrajendra
 
Java session08
Java session08Java session08
Java session08
Niit Care
 
Net framework session02
Net framework session02Net framework session02
Net framework session02
Niit Care
 

Ähnlich wie 09 iec t1_s1_oo_ps_session_13 (20)

File handling
File handlingFile handling
File handling
 
31cs
31cs31cs
31cs
 
ASP.NET Session 7
ASP.NET Session 7ASP.NET Session 7
ASP.NET Session 7
 
32sql server
32sql server32sql server
32sql server
 
Answer ado.net pre-exam2018
Answer ado.net pre-exam2018Answer ado.net pre-exam2018
Answer ado.net pre-exam2018
 
Input & output
Input & outputInput & output
Input & output
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
Java I/O
Java I/OJava I/O
Java I/O
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
NiFi - First approach
NiFi - First approachNiFi - First approach
NiFi - First approach
 
SQLBits X SQL Server 2012 Rich Unstructured Data
SQLBits X SQL Server 2012 Rich Unstructured DataSQLBits X SQL Server 2012 Rich Unstructured Data
SQLBits X SQL Server 2012 Rich Unstructured Data
 
Linkers
LinkersLinkers
Linkers
 
Java session08
Java session08Java session08
Java session08
 
Cloud Infrastructures Slide Set 7 - Docker - Neo4j | anynines
Cloud Infrastructures Slide Set 7 - Docker - Neo4j | anyninesCloud Infrastructures Slide Set 7 - Docker - Neo4j | anynines
Cloud Infrastructures Slide Set 7 - Docker - Neo4j | anynines
 
Hack the whale
Hack the whaleHack the whale
Hack the whale
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdf
 
Docker.pptx
Docker.pptxDocker.pptx
Docker.pptx
 
Net framework session02
Net framework session02Net framework session02
Net framework session02
 

Mehr von Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 b
Dacj 1-3 bDacj 1-3 b
Dacj 1-3 b
 
Dacj 1-3 a
Dacj 1-3 aDacj 1-3 a
Dacj 1-3 a
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

09 iec t1_s1_oo_ps_session_13

  • 1. Object-Oriented Programming Using C# Objectives In this session, you will learn to: Implement read and write in text files Implement read and write in binary files Implement the Windows File System Describe exceptions Ver. 1.0 Session 13 Slide 1 of 24
  • 2. Object-Oriented Programming Using C# Implementing Reading and Writing in the Text Files • The Stream class is used to read from and to write data in the text files. • It is an abstract class, which supports reading and writing bytes into it. • If data of a file is only text, then you can use the StreamReader class and the StreamWriter class to accomplish the reading and writing tasks, respectively. Ver. 1.0 Session 13 Slide 2 of 24
  • 3. Object-Oriented Programming Using C# StreamReader Class • The StreamReader class is inherited from the abstract class TextReader. • The TextReader class represents a reader which can read a series of characters. Ver. 1.0 Session 13 Slide 3 of 24
  • 4. Object-Oriented Programming Using C# StreamReader Class (Contd.) • The following table describes some of the commonly used methods of the StreamReader class. Methods Description Close Closes the object of StreamReader class and the underlying stream, and releases any system resources associated with the reader Peek Returns the next available character but does not consume it Read Reads the next character or the next set of characters from the stream ReadLine Reads a line of characters from the current stream and returns data as a string Seek Allows the read/write position to be moved to any position within the file Ver. 1.0 Session 13 Slide 4 of 24
  • 5. Object-Oriented Programming Using C# StreamWriter Class • The StreamWriter class is inherited from the abstract class TextWriter. • The TextWriter class represents a writer, which can write a series of characters. • The following table describes some of the commonly used methods of the StreamWriter class. Methods Description Close Closes the current StreamWriter object and the underlying stream Flush Clears all buffers for the current writer and causes any buffered data to be written to the underlying stream Write Writes to the stream WriteLine Writes data specified by the overloaded parameters, followed by end of line Ver. 1.0 Session 13 Slide 5 of 24
  • 6. Object-Oriented Programming Using C# Implementing Reading and Writing in Binary Files • In C#, you can directly display the contents of the file on the screen. • Binary read and write means that a number is written as a float representation consuming four bytes of space. • The BinaryReader and BinaryWriter classes are used for reading and writing the binary data in to files. Ver. 1.0 Session 13 Slide 6 of 24
  • 7. Object-Oriented Programming Using C# BinaryReader Class • The BinaryReader class is used to read binary data from a file. • The following table describes some of the commonly used methods of the BinaryReader class. Method Description Close Closes the current reader and the underlying stream Read Reads characters from the underlying stream and advances the current position of the stream Ver. 1.0 Session 13 Slide 7 of 24
  • 8. Object-Oriented Programming Using C# BinaryWriter Class • The BinaryWriter class is used to write binary data to a stream. • The following table describes some of the commonly used methods of the BinaryWriter class. Method Description Close Closes the current BinaryWriter and the underlying stream Seek Sets the position within the current stream Write Writes a value to the current stream Flush Clears all buffers for the current writer and causes any buffered data to be written to the underlying device Ver. 1.0 Session 13 Slide 8 of 24
  • 9. Object-Oriented Programming Using C# Implementing the Windows File System • The ability to browse and locate files and directories for a specific directory is essential for many programming tasks. • Using classes such as the DirectoryInfo and FileInfo classes in combination is an efficient way to gather the required information about files and directories in a specific location. Ver. 1.0 Session 13 Slide 9 of 24
  • 10. Object-Oriented Programming Using C# DirectoryInfo Class • The DirectoryInfo class is derived from the FileSystemInfo class. • The following table describes some of the commonly used properties of the DirectoryInfo class. Property Description Gets or sets attributes associated with the current file. This property is inherited Attributes from FileSystemInfo. Gets or sets CreationTime of the current file. This property is inherited from CreationTime FileSystemInfo. Exists Gets a Boolean value indicating whether the directory exist or not. Gets a string containing the file extension. This property is inherited from Extension FileSystemInfo. Gets a string containing the full path of the directory. This property is inherited from FullName FileSystemInfo. Gets the last accessed time of the directory. This property is inherited from LastAccessTime FileSystemInfo. Name Gets a string containing the name of a given file. Ver. 1.0 Session 13 Slide 10 of 24
  • 11. Object-Oriented Programming Using C# DirectoryInfo Class (Contd.) • The following table describes some of the commonly used methods of the DirectoryInfo class. Method Description Create Creates a directory. CreateSubdirectory Creates a subdirectory. Delete Deletes a directory. Returns the directories in the current directory after matching all the GetDirectories criteria. It also allows you to search subdirectories within directories. GetFiles Returns the files in the current directory. Ver. 1.0 Session 13 Slide 11 of 24
  • 12. Object-Oriented Programming Using C# FileInfo Class • The FileInfo class is derived from FileSystemInfo class. • The following table describes some commonly used properties FileInfo class. Property Description Gets or sets attributes associated with the current file. This property is inherited from Attributes FileSystemInfo. Gets or sets CreationTime of the current file. This property is inherited from CreationTime FileSystemInfo. Directory Gets an instance of the directory which the file belongs to. Exists Gets a boolean value indicating whether the file exists or not. Extension Gets a string containing the file extension. This property is inherited from FileSystemInfo. Gets a string containing the full path of the file. This property is inherited from FullName FileSystemInfo. LastAccessTime Gets the last accessed time of the file. This property is inherited from FileSystemInfo. Gets the time of the last written activity to the file. This property is inherited from LastWriteTime FileSystemInfo. Length Gets the size of the file. Name Gets a string containing the name of a given file. Ver. 1.0 Session 13 Slide 12 of 24
  • 13. Object-Oriented Programming Using C# FileInfo Class (Contd.) • The following table describes some of the commonly used methods of the FileInfo class. Method Description Create Creates a file AppendText Appends a text to the file represented by the FileInfo object Delete Deletes a file Open Opens file OpenRead Opens a file in read-only mode Ver. 1.0 Session 13 Slide 13 of 24
  • 14. Object-Oriented Programming Using C# Describing Exceptions An exception is an erroneous situation that occurs during program execution. When an exception occurs in an application, the system throws an error. The error is handled through the process of exception handling. Ver. 1.0 Session 13 Slide 14 of 24
  • 15. Object-Oriented Programming Using C# Types of Errors There are three types of errors that can occur in the application: – Syntax errors: Occurs when statements are not constructed properly, keywords are misspelled, or punctuation is omitted. – Run-time errors: Occurs when an application attempts to perform an operation, which is not allowed at runtime. – Logical errors: Occurs when an application compiles and runs properly but does not produce the expected results. Let us understand the various types of errors in detail. Ver. 1.0 Session 13 Slide 15 of 24
  • 16. Object-Oriented Programming Using C# Syntax Errors class Errors { Console.WriteLine(“Enjoy Errors”) } Semicolon is missing from Console.WriteLine statement Ver. 1.0 Session 13 Slide 16 of 24
  • 17. Object-Oriented Programming Using C# Run-Time Errors class Errors { int Num1=0; int Num2=20; int Num3; Num3=Num2/Num1; Console.WriteLine(“The Result is {0}”, Num3); } Division by zero has taken place Ver. 1.0 Session 13 Slide 17 of 24
  • 18. Object-Oriented Programming Using C# Logical Errors class Errors { int Num1=10; int Num2=2; int Num3; Num3=Num2/Num1; Console.WriteLine(“The Result is {0}”, Num3); } Expected result = 5 Present result = 0.2 Ver. 1.0 Session 13 Slide 18 of 24
  • 19. Object-Oriented Programming Using C# Exception Classes • There are many exception classes which are directly or indirectly derived from the System.Exception class. Some of these classes are: – System.ApplicationException class – System.SystemException class Ver. 1.0 Session 13 Slide 19 of 24
  • 20. Object-Oriented Programming Using C# Exception Classes (Contd.) The hierarchy of the exception classes is displayed in the following figure. System.Exception System.ApplicationException System.SystemException Ver. 1.0 Session 13 Slide 20 of 24
  • 21. Object-Oriented Programming Using C# Exception Classes (Contd.) • The System.SystemException acts as a base class for all the predefined system exceptions. The following table describes some of the classes derived from the System.SystemException class. Exception Classes Description System.IO.IOException Handles I/O errors System.IndexOutOfRangeException Handles errors generated when a method refers to an array element, which is out of its bound System.NullReferenceException Handles errors generated during the process of dereferencing a null object System.DivideByZeroException Handles errors generated during the process of dividing the dividend with zero System.InvalidCastException Handles errors generated during typecasting System.OutOfMemoryException Handles memory allocation to the application errors Ver. 1.0 Session 13 Slide 21 of 24
  • 22. Object-Oriented Programming Using C# Summary In this session, you learned that: – The Stream class is used to read and write data to the text files. It is an abstract class, which supports reading and writing bytes into it. – The StreamReader class is inherited from the abstract class TextReader. The TextReader class represents a reader which can read a series of characters. – The StreamWriter class is inherited from the abstract class TextWriter. The TextWriter class represents a writer, which can write a series of characters. – The BinaryReader class allows reading of binary data from a file. – The BinaryWriter class allows writing of binary data to a stream. Ver. 1.0 Session 13 Slide 22 of 24
  • 23. Object-Oriented Programming Using C# Summary (Contd.) – The DirectoryInfo class is derived from FileSystemInfo class and it works on a specific directory and shows the fullpath of the current directory. – The FileInfo class is derived from FileSystemInfo class and it works on a specific directory to display the list of all the files. – An exception is an erroneous situation that occurs during program execution. – A syntax error occurs when a compiler cannot compile the code. This may happen when the statements are not constructed properly, keywords are misspelled, or punctuation is omitted. – A run-time error occurs when an application attempts to perform an operation that is not allowed. Ver. 1.0 Session 13 Slide 23 of 24
  • 24. Object-Oriented Programming Using C# Summary (Contd.) A logical error occurs when an application compiles and runs properly but does not produce the expected results. Exceptional conditions arise when an operation cannot be completed normally during the processing of C# statements and expressions. Ver. 1.0 Session 13 Slide 24 of 24

Hinweis der Redaktion

  1. Students have learnt the structure of different types of dimensions and the importance of surrogate keys in Module I. In this session, students will learn to load the data into the dimension tables after the data has been transformed in the transformation phase. In addition, students will also learn to update data into these dimension tables. Students already know about different types of dimension tables. Therefore, you can start the session by recapitulating the concepts. Initiate the class by asking the following questions: 1. What are the different types of dimensions? 2. Define flat dimension. 3. What are conformed dimension? 4. Define large dimension. 5. Define small dimension. 6. What is the importance of surrogate key in a dimension table? Students will learn the loading and update strategies theoretically in this session. The demonstration to load and update the data in the dimension table will be covered in next session.
  2. Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
  3. Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
  4. Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
  5. Student already have learnt about type 2 SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 2 SCDs? Given an example to explain type 2 SCDs. This will recapitulate what they have learnt about type 2 SCD in Module 1. Now explain the strategy to update the data into these dimension tables with help the example given in SG. After explaining the examples, you can ask students to think of an example of a type 2 SCD and then tell the strategy to update the data into this dimension table.
  6. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  7. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  8. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  9. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  10. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  11. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  12. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  13. Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
  14. Students know the importance of surrogate keys. In this session students will learn the strategy to generate the surrogate key. Give an example to explain the strategy to generate the surrogate keys by concatenating the primary key of the source table with the date stamp. For example, data from a Product table has to be loaded into the Product_Dim dimension table on Feb 09, 2006. The product_code is the primary key column in the Product table. To insert the surrogate key values before loading the data into the dimension table, you can combine the primary key value with the date on which the data has to be loaded. In this case the surrogate key value can be product_code+09022006.
  15. Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
  16. Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
  17. Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
  18. Student already have learnt about type 2 SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 2 SCDs? Given an example to explain type 2 SCDs. This will recapitulate what they have learnt about type 2 SCD in Module 1. Now explain the strategy to update the data into these dimension tables with help the example given in SG. After explaining the examples, you can ask students to think of an example of a type 2 SCD and then tell the strategy to update the data into this dimension table.
  19. You can summarize the session by running through the summary given in SG. In addition, you can also ask students summarize what they have learnt in this session.
  20. You can summarize the session by running through the summary given in SG. In addition, you can also ask students summarize what they have learnt in this session.
  21. You can summarize the session by running through the summary given in SG. In addition, you can also ask students summarize what they have learnt in this session.