Results 1 to 6 of 6

Thread: Object Typecasting in C sharp

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    Object Typecasting in C sharp

    Hello friend,

    I need your help to know about the Object Typecasting of C sharp. According to my knowledge the typecasting means the conversion of one datatype value into the another datatype. But I am not getting the meaning of Object Typecasting. I have searched many websites for this but didn't get proper details. If you have knowledge about the 'Object Typecasting' in C sharp, then please let me know that. I am waiting for your reply.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Object Typecasting in C sharp

    Hi friend,

    The object Typecasting in C sharp divided into following categories:
    • User-defined conversions
    • Implicit conversions
    • Conversions with helper classes
    • Explicit conversions (casts)

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Object Typecasting in C sharp

    In the implicit Object Typecasting in C sharp doesn't have any special syntax . This is because the conversion is type safe and which doesn't leads to any data loss. But this opposite in explicit object typecasting, i.t it needs 'cast operator'. In this type of casting destination and source variables are compatible. But disadvantage of this type casting is that it leads to the loss of data. This is because the smaller size of destination datatype than source datatype.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Object Typecasting in C sharp

    Hi,

    I suggest you to refer following example of 'Object Typecasting':
    Code:
    #include <iostream>
    
    using namespace std;
    
    class CDummy1
     {
        float i7,j7;
    };
    
    class CAddition1 {
    	int x7,y7;
      public:
    	CAddition (int a7, int b7) { x7=a7; y7=b7; }
    	int result() { return x7+y7;}
    };
    
    int main () {
      CDummy1 d2;
      CAddition * padd;
      padd = (CAddition*) &d;
      cout << padd->result();
      return 0;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Object Typecasting in C sharp

    The Object Typecasting is divided into up-casting and down casting. The up- casting occurs when we trying to assign the higher data type value to the lower data tape variable. While the down-casting occurs when we trying to assign the lower data type value to the higher data type variable. It is also possible to make down-casting for class objects in C sharp programming.

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Object Typecasting in C sharp

    Explicit Object Typecasting is a type conversion and which is explicitly defined in a program. Implicit Object Typecasting can be created when the value to be stored can fit into the variable without any truncation or any rounded off. If a Object Typecasting cannot be created without a risk of losing information, the compiler requires that you perform an explicit conversion, which is called a cast.

Similar Threads

  1. Replies: 6
    Last Post: 06-06-2011, 01:34 AM
  2. Sharp 007SH Hybrid An 3D Clamshell Android Phone by Sharp
    By jackalz in forum Web News & Trends
    Replies: 3
    Last Post: 22-05-2011, 07:28 AM
  3. Replies: 3
    Last Post: 08-01-2011, 06:20 AM
  4. Differents between object and static object
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 01:11 PM
  5. What is typecasting and how does it work in C programming
    By AMISH in forum Software Development
    Replies: 5
    Last Post: 06-11-2009, 10:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,030,365.75474 seconds with 16 queries