C # append () Usage

Source: Internet
Author: User

Append () Usage

Class preson

{

Private string firstname;

Private string middletname;

Private string lastname; // defines three private variables: firstname middlename lastname

Public preson (string FN, string Mn, string ln) // Constructor

{

Firstname = FN;

Middlename = Mn;

Lastname = ln;

}

Public void displayfull name () // define a method name

{

Stringbuilder fullname = new stringbuilder (); // instantiate fullname

Fullname. append (firstname); // fullname = fullname + firstname full is empty. Only firstname is displayed.

Fullname. append (""); // fullname = fullname + "space" fullname already contains the value of firstname

If (middlename [0]! = "") // If the character in the first array of the intermediate name is not empty, run downward. Otherwise, the IF statement is displayed.

{

Fullname. append ("."); // if the condition is met, continue fullname = fullname + "."

Fullname. append (lastname); // value of fullname = fullname + lastname

Console. writeline (fullname); // output fullname

}

}

Public static void main ()

{

Person me = new person ("Bradley", "Lee", "Jones"); // instantiate

Me. displayfullname (); // call this function

}

Output result: Bradley L. Jones

Explanation: fullname-> Bradley assigns a value first.

Fullname-> Bradley _ add a space ("_" indicates that the space is not an underline)

Fullname-> bradley_l

Fullname-> bradley_l.

Fullname-> bradley_l.jones

Fullname = Bradley L. Jones

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.