SlideShare a Scribd company logo
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

More Related Content

PPS
04 iec t1_s1_oo_ps_session_05
PPS
06 iec t1_s1_oo_ps_session_08
PPS
08 iec t1_s1_oo_ps_session_11
PPS
05 iec t1_s1_oo_ps_session_07
PPS
07 iec t1_s1_oo_ps_session_10
PPS
12 iec t1_s1_oo_ps_session_17
PPS
11 iec t1_s1_oo_ps_session_16
PPS
10 iec t1_s1_oo_ps_session_14
04 iec t1_s1_oo_ps_session_05
06 iec t1_s1_oo_ps_session_08
08 iec t1_s1_oo_ps_session_11
05 iec t1_s1_oo_ps_session_07
07 iec t1_s1_oo_ps_session_10
12 iec t1_s1_oo_ps_session_17
11 iec t1_s1_oo_ps_session_16
10 iec t1_s1_oo_ps_session_14

What's hot (20)

PPS
01 iec t1_s1_oo_ps_session_01
PPS
03 iec t1_s1_oo_ps_session_04
PPS
13 iec t1_s1_oo_ps_session_19
PPS
01 gui 01
PPS
Java session02
PPS
Java session01
PPS
Dacj 1-3 c
PPT
Csharp
PDF
Win32/Flamer: Reverse Engineering and Framework Reconstruction
PPT
C Course Material0209
PPS
C programming session 14
PDF
NDK Primer (Wearable DevCon 2014)
PDF
Tutorial c#
PDF
NDK Primer (AnDevCon Boston 2014)
PPS
02 iec t1_s1_plt_session_02
PPS
Dacj 1-2 a
PPT
Dot net introduction
PPTX
Session2 (3)
DOCX
C# Unit 2 notes
DOCX
.Net framework components by naveen kumar veligeti
01 iec t1_s1_oo_ps_session_01
03 iec t1_s1_oo_ps_session_04
13 iec t1_s1_oo_ps_session_19
01 gui 01
Java session02
Java session01
Dacj 1-3 c
Csharp
Win32/Flamer: Reverse Engineering and Framework Reconstruction
C Course Material0209
C programming session 14
NDK Primer (Wearable DevCon 2014)
Tutorial c#
NDK Primer (AnDevCon Boston 2014)
02 iec t1_s1_plt_session_02
Dacj 1-2 a
Dot net introduction
Session2 (3)
C# Unit 2 notes
.Net framework components by naveen kumar veligeti
Ad

Viewers also liked (20)

PPS
Vb.net session 09
PPS
11 ds and algorithm session_16
PPS
15 ooad uml-20
PPS
Dacj 2-2 c
PPS
Oops recap
PDF
OOP Java
PPS
Rdbms xp 01
PPS
Jdbc session01
PPS
14 ooad uml-19
PPS
Deawsj 7 ppt-2_c
PDF
Java Garbage Collection - How it works
PPS
Ds 8
PDF
Understanding Java Garbage Collection - And What You Can Do About It
PPS
Aae oop xp_06
PPS
Dacj 1-1 a
PDF
JAVA Object Oriented Programming (OOP)
PDF
Chapter 21 c language
PPS
Ajs 4 a
PPTX
Introduction to programming
Vb.net session 09
11 ds and algorithm session_16
15 ooad uml-20
Dacj 2-2 c
Oops recap
OOP Java
Rdbms xp 01
Jdbc session01
14 ooad uml-19
Deawsj 7 ppt-2_c
Java Garbage Collection - How it works
Ds 8
Understanding Java Garbage Collection - And What You Can Do About It
Aae oop xp_06
Dacj 1-1 a
JAVA Object Oriented Programming (OOP)
Chapter 21 c language
Ajs 4 a
Introduction to programming
Ad

Similar to 09 iec t1_s1_oo_ps_session_13 (20)

PPTX
15. Streams Files and Directories
PPT
File handling
PPTX
04 standard class library c#
PPTX
PPTX
32sql server
PPT
ASP.NET Session 7
PDF
Writing Usable APIs in Practice by Giovanni Asproni
PDF
Tool Development 03 - File I/O
PPT
Advanced c#
PPTX
2CPP17 - File IO
PPTX
C# File IO Operations
PPT
C# Tutorial MSM_Murach chapter-21-slides
PPT
Java Basics
DOCX
Switching & Multiplexing
PDF
Intake 38 10
PPTX
31cs
PPT
Md121 streams
PPTX
Input & output
PDF
Java IO
15. Streams Files and Directories
File handling
04 standard class library c#
32sql server
ASP.NET Session 7
Writing Usable APIs in Practice by Giovanni Asproni
Tool Development 03 - File I/O
Advanced c#
2CPP17 - File IO
C# File IO Operations
C# Tutorial MSM_Murach chapter-21-slides
Java Basics
Switching & Multiplexing
Intake 38 10
31cs
Md121 streams
Input & output
Java IO

More from Niit Care (20)

PPS
Ajs 1 b
PPS
Ajs 4 b
PPS
Ajs 4 c
PPS
Ajs 3 b
PPS
Ajs 3 a
PPS
Ajs 3 c
PPS
Ajs 2 b
PPS
Ajs 2 a
PPS
Ajs 2 c
PPS
Ajs 1 a
PPS
Ajs 1 c
PPS
Dacj 4 2-c
PPS
Dacj 4 2-b
PPS
Dacj 4 2-a
PPS
Dacj 4 1-c
PPS
Dacj 4 1-b
PPS
Dacj 4 1-a
PPS
Dacj 1-2 b
PPS
Dacj 1-3 b
PPS
Dacj 1-3 a
Ajs 1 b
Ajs 4 b
Ajs 4 c
Ajs 3 b
Ajs 3 a
Ajs 3 c
Ajs 2 b
Ajs 2 a
Ajs 2 c
Ajs 1 a
Ajs 1 c
Dacj 4 2-c
Dacj 4 2-b
Dacj 4 2-a
Dacj 4 1-c
Dacj 4 1-b
Dacj 4 1-a
Dacj 1-2 b
Dacj 1-3 b
Dacj 1-3 a

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
A novel scalable deep ensemble learning framework for big data classification...
A Presentation on Artificial Intelligence
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
Chapter 5: Probability Theory and Statistics
Group 1 Presentation -Planning and Decision Making .pptx
Tartificialntelligence_presentation.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Encapsulation_ Review paper, used for researhc scholars
A comparative analysis of optical character recognition models for extracting...
Univ-Connecticut-ChatGPT-Presentaion.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Web App vs Mobile App What Should You Build First.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Mushroom cultivation and it's methods.pdf
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A comparative study of natural language inference in Swahili using monolingua...
A novel scalable deep ensemble learning framework for big data classification...

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

Editor's Notes

  • #2: 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.
  • #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: 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.
  • #6: 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.
  • #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: 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.
  • #15: 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.
  • #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.
  • #20: 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.
  • #21: 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.
  • #22: 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.
  • #23: 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.
  • #24: 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.
  • #25: 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.