override ToString : ToString : Class C# Examples


C# Examples » Class » ToString »

 

override ToString









    
using  System;
using  System.Collections;
      
struct  RGB
{
        public  int  red;
        public  int  green;
        public  int  blue;
      
        public  RGB(int  red,  int  green,  int  blue)
        {
                this.red  =  red;
                this.green  =  green;
                this.blue  =  blue;
        }
      
        public  override  String  ToString()
        {
                return  red.ToString("X")  
                        +  green.ToString("X")  
                        +  blue.ToString("X");
        }
}
      
class  BoxTest
{
        static  ArrayList  rgbValues;
      
        public  static  void  Main()
        {
                RGB  rgb  =  new  RGB(255,  255,  255);
      
                rgbValues  =  new  ArrayList();
                rgbValues.Add(rgb);
      
                Console.WriteLine("The  RGB  value  is  {0}",  rgb);
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» ToString