0% found this document useful (0 votes)
2 views

C# Programming Notes

The document discusses key concepts in C# programming, including nullable types that allow value types to be assigned null, and exception handling techniques to manage runtime errors gracefully. It also covers the System.Media namespace, which includes classes like SoundPlayer for playing sound files, and notes that this namespace is not available in .NET Core or later versions. Overall, the document serves as an introduction to essential C# programming elements and sound management in applications.

Uploaded by

moekadi.molefe
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C# Programming Notes

The document discusses key concepts in C# programming, including nullable types that allow value types to be assigned null, and exception handling techniques to manage runtime errors gracefully. It also covers the System.Media namespace, which includes classes like SoundPlayer for playing sound files, and notes that this namespace is not available in .NET Core or later versions. Overall, the document serves as an introduction to essential C# programming elements and sound management in applications.

Uploaded by

moekadi.molefe
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

C# Programming

By Lihle Zulu
Objectives

Explain the
Explain the Arrays & String
purpose of System.Media
purpose of a manipulation
exception Namespace
nullable type. and methods
handling.
• a value type cannot be assigned a null
value. For example, int i = null will give
you a compile time error.
• C# 2.0 introduced nullable types that
allow you to assign null to value type
variables. You can declare nullable types
Nullable using Nullable<t>where T is a type.
Type • Nullable<int> i = null;
• A nullable type can represent the correct
range of values for its underlying value
type, plus an additional null value. For
example, Nullable<int> can be assigned
any value from -2147483648 to
2147483647, or a null value.
Nullable Type

• The Nullable types are


instances of
System.Nullable<T> struct.
Think it as something like the
following structure.
Nullable
Type
• A nullable of type int
is the same as an
ordinary int plus a
flag that says
whether the int has a
value or not (is null
or not). All the rest is
compiler magic that
treats "null" as a
valid value.
Strings
• Is a sequence of
characters put
together.
Cont’d
Cont’d
Cont’d
Arrays Common Methods
Array Cont’d
System.Object Class
System.Object Cont’d
Console Class
Console Cont’d
Console Cont’d
Console Cont’d
• Gracefully manage runtime errors by
detecting and handling unexpected
situations that might occur during
program execution.
• Allowing the application to continue
running even when encountering
Exception issues like invalid input, file access
Handling errors, or network problems.
• Instead of crashing abruptly; this is
achieved through the use of "try",
"catch", and "finally" blocks to
isolate potentially problematic code
and provide appropriate responses
to errors.
Exception Handling
Example
of
Runtime
Error
Solution
System.Media
Namespace
• Contains classes for playing sound files
and accessing sounds provided by the
system.
• The following classes are included in this
namespace:
• A SoundPlayer class for loading and
playing sounds in various file formats.
• A SystemSound class for
representing and playing a system
sound.
• A SystemSounds class that retrieves
sounds associated with a set of
Windows operating system sound-
event types.
SoundPlayer Class

• The SoundPlayer class is part of the


System.Media namespace in C#. It
provides an easy way to play sound files,
specifically WAV (.wav) files, in your
application.
• It supports both synchronous and
asynchronous sound playback.
• The primary purpose of the SoundPlayer
class is to facilitate simple audio playback,
making it useful for applications that need
sound effects or audio cues, such as
games, notifications, or any system that
requires sound output.
Target Framework
Compatibility

• The System.Media namespace and its


SoundPlayer class are available in .NET
Framework, but they are not available
in .NET Core or .NET 5/6/7+.
• If you're using a .NET Core or .NET
5/6/7+ project, you will need to use an
alternative approach for playing
sounds. System.Media is not supported
in these frameworks.
SoundPlayer Class

You might also like