http://csharpforwings.blogspot.com/ | |
Hello experts of C# plz check out this lesson and give your Precious comments
10:33, 2007-Nov-2
.. 0 comments
.. Link
LESSON : Boxing & Un-Boxing C# has a number of features; in this lesson, we are going to discuss about a special feature called “Boxing & Un-Boxing”. First we’ll see about what is meant by “Boxing” When a variable of value type needs to be converted to reference type, an object box is allocated to hold the value; and the value is copied into that box. This process of copying a value to a box is called Boxing. Analogy: It’s similar to that process of transferring data from a Floppy disk to our PC .Likewise in boxing it is possible to convert a value type object to reference type object. Un-Boxing: Un-Boxing is the reverse process of Boxing i.e. converting reference type back to the value type is known as Un-Boxing. When an object box is cast back to its original value type, the value is copied out of that box into the appropriate storage location. For example: Similar to re – transferring the data from our PC to a Floppy disk Drive reconverting like wise un-boxing will convert reference type into value type objects. Here’s a sample program which gives you a better understanding.
class Boxing { static void { int a = 123; //variable declarations object box = a; // boxing Console.WriteLine("Value of Boxed Object {0}",box); //printing the value here int b = (int) box; // unboxing Console.WriteLine(“Value of Un-Boxed Object {0}”,b); //printing the converted value here Console.ReadLine(); } } In the sample program, we have used both the boxing and un-boxing features. This line is very much familiar to us. Let’s declare a namespace “System” here. Then we are creating a class namely “Boxing”. In the main method, we declare a variable namely “a” with integer type. And we have also assigned the value of “a” is equal to “123”. Now, we are going to box the value “123”. For that, we are creating an object namely “box” and we also assign the variable ‘a’ to the box object. The value of “a” is transferred to the object “box” while compiling this line. Here, we can verify the content in the object box using “Write line” method. Next, we are un-boxing the content of the object “box” and stored it in the variable “b”. When the compiler compiles this line, object “box” content will be transferred to “b”. To verify the content in “b” also we can use the Write line method. Save the application with .cs extension. Let’s save it as “boxing.cs” Well, now we build our application. In Visual Studio .NET command prompt, type file name with extension; then press enter Let’s type the name as “boxing.cs” Here’s our file successfully executed. Open “exe” file to check output. This line “Value of Boxed Object” is “123” which indicates that we have boxed the value. And “Value of Un-Boxed Object” is “123” which indicates that we have un-boxed the boxed value. This lesson ends up with “Boxing & Un-Boxing”. I hope you are clear with this concept. In the next lesson, we will discuss some more interesting topics. plz help me to help others
06:15, 2007-Nov-1
.. 0 comments
.. Link
Hi experts of C# - am karthi from worlds northeast team. Our team goal is to give software knowledge to all layperson around the world. We are developing content for all leading softwares, am in C# domain. Plz help me to help others. Chapter 1 Author Mentoring
1 Audience - Who can learn? 2 Employment Opportunities and Job Roles 3 Prerequisite Knowledge and Skills 4 Inspire Chapter 2 Fundamentals of C#
5 History of C# 6 What is C#? 7 Why C#? 8 Course Objective Chapter 3 Setting up an Environment 9 Hardware/Software Requirements 10 Installation Process 11 Trouble Shooting Chapter 4 Introduction 12 About .NET Framework 13 Architecture of .NET Framework 14 Common Language Runtime(CLR) 15 Working of CLR 16 Just-In-Time Compiler. 17 Cross-Language Interoperability 18 Garbage Collection 19 Common Type System(CTS) 20 Common Language Specification(CLS) 21 My First C# program Chapter 5 Window Forms & Windows Application 22 Introduction to Visual Studio 23 Visual Studio .Net IDE 24 Menus & Tool Box 25 Type’s of Windows in Visual C# 26 Creating a Windows Application 27 Understanding the code Chapter 6 C# Fundamental
28 Data types 29 Boxing & Un-Boxing 30 Variables 31 Strings 32 Constants 33 Flow Control of Conditional Statements 34 Jumping Statement 35 Loop in C# 36 Simple Program using Statements 37 Structures & Pre-processors 38 Operators 39 Operator Overloading Chapter 7 Programming Fundamental 40 Classes and Objects 41 Fields & Properties 42 Methods 43 Delegates & Events 44 Arrays & Indexers 45 Namespaces 46 Assemblies 47 Constructors & Destructors 48 Exception Handling 49 Threading Chapter 8 Object-Oriented Programming 50 Principles of Object-Oriented Programming 51 Inheritance 52 Polymorphism 53 Encapsulation 54 Interfaces Chapter 9 Data Access in ADO.NET 55 Introduction to ADO.NET 56 Different Component Of ADO.NET 57 Review of basic SQL Queries 58 Defining a Connection 59 Connecting Database using ADO.NET 60 Defining the Data adapter 61 Manipulating the Record 62 Using Stored Procedure with ADO.NET Chapter 10 Web forms, Web controls & Web services 63 Creating and Running a Simple Web Form 64 Introduction to Web service 65 Creating a Web Service 66 Securing Web Application |
About MeMy Profile Archives Friends My Photo Album LinksCategoriesRecent EntriesHello experts of C# plz check out this lesson and give your Precious commentsplz help me to help others Friends |