C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Boxing


Posted Date: 29 May 2007    Resource Type: Code Snippets    Category: C# Syntax
Author: Abbas KapasiMember Level: Bronze    
Rating: 1 out of 5Points: 7



Function Square () returns the boxed square of a value if the data type is
int or double. Otherwise, Square() returns a null reference.



using System;

public class Boxing
{
static public void Main ()
{
double d = 5;
// Pass a double to Square ()
object o = Square (d);
ShowSquare (o);
// Pass an int to Square ()
o = Square (10);
ShowSquare (o);
// Pass a float to Square ()
o = Square (2.5F);
ShowSquare (o);
}

static object Square (object o)
{
if (o is double)
return ((double) o * (double) o);
if (o is int)
return ((int) o * (int) o);
return (null);
}

static public void ShowSquare (object o)
{
if (Object.Equals (o, null))
Console.WriteLine ("The object is null");
else
Console.WriteLine ("The square is " + o);
}
}






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Email validation using regular expressions
Previous Resource: Mail Notification
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use