You are on page 1of 4

C# ASSIGNMENT 1

Submitted to: Respected Mr. Shahzad Hussain

MARCH 30, 2020


NAME: HAMZA AKHTAR
Reg# CS171017
1. Briefly describe the major components of the .NET Framework
and describe what each component does?

Ans: The .NET framework is a managed, type safe environment for application
development and execution.
The.NET Framework consists of two main components:

1.The Common Language Runtime (CLR)


2.The .NET Framework Class Library

CLR: CLR provides interoperability between different language, like C# , VB,


Visual C++, by providing a common environment for the execution of code
written in of these languages.

.NET class Library: .NET framework contains multiple classes that are readily
available for developers. The classes in the FCL (framework class library) are
grouped under multiple namespaces.

2. Briefly explain what is meant by a reference type and value type?


Ans: The Types in .NET Framework are either treated by Value Type or by
Reference Type.

A Value Type holds the data within its own memory allocation and a Reference Type
contains a pointer to another memory location that holds the real data. Reference
Type variables are stored in the heap while Value Type variables are stored in the
stack.

Value Type e.g.

Here, int x= 10;

Reference Type e.g.

Here, int [] iArray = new int[20];


3. How do you enable your application to use .NET base class
library member without referencing their fully qualified names?

Ans: Use the Imports keyword (Visual Basic .NET) or the using keyword (Visual
C#) to make a .NET Framework namespace visible to your application.

' This namespace contains a class called Class1.


Imports MyProj1
' This namespace also contains a class called Class1.
Imports MyProj2

4. Briefly describe how garbage collection works?

Ans: Garbage collector of .NET tries to compact the memory in such a way as to
increase the working space required for heap. The class GC of .NET class library
controls the garbage collector. The core task of performing a collection is executed
by the GC’s optimizing engine that determines the best time to perform collection
based on allocations being made.

5. Briefly describe what members are and list the four types of
members?

Ans: Members are the parts of a class or a structure that hold data or implement
functionality. The primary member types are fields, properties, methods, and
events.

6. Explain what constructors and destructors are and describe what


they are used for?

Ans: The constructor is the method that initializes a class or structure and is run
when a type is first instantiated. It is used to set default values and perform other
tasks required by the class. A destructor is the method that is run as the object is
being reclaimed by garbage collection. It contains any code that is required for
cleanup of the object.
7. Briefly explain the difference between public, internal and private
access levels as they apply to user-defined types and member?

Ans: In user-defined types:


• Public (public) classes can be instantiated by any element of the application.
• Friend (internal) classes can be instantiated only by members of the same
assembly.
• Private (private) classes can be instantiated only by themselves or types they
are nested in.
Likewise, a Public (public) member can be accessed by any client in the
application, a Friend (internal) member can be accessed only from members of the
same assembly, and Private (private) members can be accessed only from within
the type.

8. Do you need to instantiate a class before accessing a static


member Why or why not?

Ans: Because a Shared (static) member belongs to the type rather than to any
instance of the type, you can access the member without first creating an instance
of the type.

You might also like