0% found this document useful (0 votes)
3 views1 page

C# Program Structure

The document outlines a simple C# program structure, including the use of namespaces, class declarations, and the Main() method as the entry point for execution. It also explains the concepts of boxing and unboxing, specifically how a value type is converted to a reference type. An example is provided demonstrating boxing with an integer variable being wrapped in an object and displayed.

Uploaded by

amansilani92
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)
3 views1 page

C# Program Structure

The document outlines a simple C# program structure, including the use of namespaces, class declarations, and the Main() method as the entry point for execution. It also explains the concepts of boxing and unboxing, specifically how a value type is converted to a reference type. An example is provided demonstrating boxing with an integer variable being wrapped in an object and displayed.

Uploaded by

amansilani92
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

C# simple program structure

using System;

namespace HelloWorldApplication
{
class Program
{
static void Main(string[] args)
{
[Link]("Hello BCA IV sem student");
[Link]("Hello ");

}}}
using Directives: These statements import namespaces, allowing you to use the classes
and methods
Namespace Declaration: A namespace is used to organize code and is a container for
related classes, structs
Class Declaration: C# is an object-oriented language, and program logic is defined within
classes.
Main() Method: This is the primary entry point where program execution begins
Statements and Expressions: Inside methods, instructions are executed sequentially
Boxing and unboxing
Boxing

The process of converting a Value Type variable (char, int etc.) to a Reference Type variable
(object) is called Boxing. Boxing is an implicit conversion process where a value type is
wrapped inside an object instance and stored on the heap. Value-type variables are
generally stored on the stack when they are local variables. When they are fields within a
reference type, they are part of the heap-allocated memory for the reference type. Reference
type variables store memory addresses (references) on the stack, while their actual data is
stored
using System;
class BCA
{
static public void Main()
{
// assigned int value
// 23 to number
int number = 23;

// boxing
object obj = number;

// Display the value of obj


[Link]("Value of object is: " + obj);

}
}

You might also like