0% found this document useful (0 votes)
5 views4 pages

CSharp Unit2 Notes

This document provides an overview of C# data types, including value types, reference types, and pointer types, along with their characteristics and examples. It also explains the concepts of boxing and unboxing, and discusses the advantages of using class libraries in .NET for efficient software development. Overall, C# is presented as a powerful, modern programming language with strong support for object-oriented programming and rich library resources.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

CSharp Unit2 Notes

This document provides an overview of C# data types, including value types, reference types, and pointer types, along with their characteristics and examples. It also explains the concepts of boxing and unboxing, and discusses the advantages of using class libraries in .NET for efficient software development. Overall, C# is presented as a powerful, modern programming language with strong support for object-oriented programming and rich library resources.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT – II : C# Data Types, Characteristics, Boxing &

Class Libraries

4(a). Various Data Types Supported by C#

Data types specify what kind of value a variable can store and how much memory it uses. C# supports Value Types,
Reference Types, and Pointer Types.

Classification of Data Types

C# Data Types

Value Types → int, float, double, char, bool


Reference Types → string, array, class, object
Pointer Types → store memory addresses

Value Types

Value types directly store values and are stored in stack memory.

Examples:
int age = 20;
float marks = 85.5f;
char grade = 'A';
bool result = true;

Reference Types

Reference types store addresses of data in heap memory.

Examples:
string name = "Mustafa";
object obj;
array, class, interface etc.

Pointer Types

Pointer types store memory addresses and are used in unsafe code.
Example:
int* ptr;

Features of C# Data Types

1. Strongly typed language


2. Type safety
3. Automatic initialization
4. Rich set of built-in types
5. Supports user-defined data types

4(b). What is C#?

C# (C Sharp) is a modern, object-oriented programming language developed by Microsoft. It is used for creating
Windows applications, web applications, mobile apps, and games using the .NET Framework.

Characteristics of C#

1. Object-oriented language
2. Simple and easy syntax
3. Type safe
4. Automatic garbage collection
5. Secure programming language
6. Rich library support
7. Component-oriented
8. Structured programming support

Architecture of C#

+----------------------------------+
| C# Application |
+----------------------------------+
| .NET Framework |
+----------------------------------+
| CLR + Framework Libraries |
+----------------------------------+
| Operating System |
+----------------------------------+

Advantages of C#
1. Easy to learn
2. Fast application development
3. Better security
4. Reusable code
5. Automatic memory management

5(a). Boxing

Boxing is the process of converting a value type into a reference type (object type).

Example:
int num = 100;
object obj = num;

Boxing Diagram

Before Boxing:
Stack Memory → num = 100

After Boxing:
Heap Memory → object obj = 100

Unboxing

Unboxing is the process of converting an object type back into a value type.

Example:
object obj = 100;
int num = (int)obj;

Difference Between Boxing and Unboxing

Boxing Unboxing Value type to object type Object type to value type Automatic conversion Explicit conversion
Stored in heap Stored in stack

5(b). Class Libraries in .NET

A class library in .NET is a collection of reusable classes, methods, interfaces, and components. It helps developers
avoid writing code repeatedly.
Framework Class Library (FCL)

FCL is the main library of the .NET Framework.

Examples:
System → Basic classes
[Link] → File handling
[Link] → Database operations
[Link] → Web applications

Architecture of Class Library

+----------------------------------+
| User Applications |
+----------------------------------+
| Framework Class Library |
|----------------------------------|
| [Link] |
| [Link] |
| [Link] |
| [Link] |
+----------------------------------+
| CLR |
+----------------------------------+

Advantages of Class Libraries

1. Reduces coding effort


2. Saves development time
3. Improves code reusability
4. Easy maintenance
5. Faster application development

Conclusion

C# is a powerful programming language used with the .NET Framework. Features like data types, boxing/unboxing,
and class libraries make software development easier, secure, and efficient.

You might also like