C # constructor and initialization list

Source: Internet
Author: User
1   //  Namespace Declaration  2   Using  System;  3   4   //  Helper class  5   Class  Outputclass  6   {  7       String Mystring;  8   9       //  Constructor  10       Public Outputclass ( String  Inputstring)  11   {  12 Mystring = Inputstring;  13   }  14  15       //  This points to a specific object, which produces calls to its own constructor with parameters.  16       Public Outputclass (): This ( "  Default string  "  )  17   {  18   }  19   20       // Instance method  21       Public   Void  Printstring ()  22   {  23 Console. writeline ( "  {0}  "  , Mystring );  24   }  25   26       // Destructor  27 ~ Outputclass ()  28   {  29           //  Some resource cleanup routines  30   }  31   }  32   33   //  Program start class  34  Class  Exampleclass  35   {  36       //  Main begins program execution.  37       Public   Static   Void  Main ()  38   {  39           //  Instance of outputclass 40 Outputclass outcl = New  Outputclass ();  41           42 Outputclass outc2 = New Outputclass ( "  This is printed by the output class.  "  );  43   44           //  Call output class 'method  45  Outcl. printstring ();  46   47   Outc2.printstring ();  48   }  49 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.