Results 1 to 3 of 3

Thread: How to dominate ToString() method in C#?

  1. #1
    PerrySullivan is offline Senior Member
    Join Date
    Dec 2009
    Posts
    209
    Rep Power
    3

    Default How to dominate ToString() method in C#?

    I am last year bsc(IT) student. Currently i am learning C# programming language. I want detailed information about How to override ToString() method in C#?. Can anybody tell me how to override ToString() method in C# with example. Thanks in advanced.

  2. #2
    RussellBarnes is offline Senior Member
    Join Date
    Dec 2009
    Posts
    214
    Rep Power
    3

    Default

    You can state ToString method with the following modifiers:

    Code:
    public override string ToString(){}
    Just try to understand this code. The following code returns the data exact to a particular instance of the class
    class PersonEg
    { 
      string Ename;
      int ECode;
      SampleObject(string Ename, int ECode)
      {
      this.Ename = Ename;
      this.ECode = ECode;
      }
      public override string ToString() 
      {
         string ss = ECode.ToString();
         return "Persons: " + Ename + " " + ss;
      }
    }

  3. #3
    PetersonClark is offline Senior Member
    Join Date
    Dec 2009
    Posts
    202
    Rep Power
    3

    Default

    I suggest you to refer following example of ToString method, which will give you something idea about the use of ToString method inherited from System.Object using private variables:

    Code:
    public class MyClassEg
    {
       private string customername ="";
       private int customersIDs = 0;
     
       public string CustomersName
       {
          get { return customername; }
          set { customername = values; }
       }
     
       public int CustomersIDs
       {
          get { return customersIDs; }
          set { customersIDs = values; }
       }
     
       public override string ToString()
       {
          return string.Format s("Customers = {0} ID = {1}", Customers, CustomersIDs);
       }
     
    }

Similar Threads

  1. Method to act Internet Security
    By LewisClark in forum General Internet Terms
    Replies: 0
    Last Post: 08-20-2010, 02:12 PM
  2. Asus Crosshair IV method
    By OrtizCooper in forum other peripherals
    Replies: 0
    Last Post: 08-07-2010, 02:08 PM
  3. override ToString() method in C#
    By Devante Swann in forum Programming
    Replies: 2
    Last Post: 02-24-2010, 11:24 AM
  4. Samsung and Hynix RAM dominate
    By adam green in forum Latest Hardware News
    Replies: 0
    Last Post: 02-02-2010, 06:44 AM
  5. Method to reinstall Windows
    By techno23 in forum Windows Vista
    Replies: 0
    Last Post: 02-16-2008, 09:29 AM

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
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48