#962 – Statements Can Span Multiple Lines

Single statements in C# (as opposed to a block of statements enclosed in curly braces) are typically written on a single line and terminated by a semicolon.

The code fragment below contains two statements, one that initializes an instance of a Dog and one that invokes the Bark method on that instanceEach of the statements is terminated by a semicolon.

Dog d1 = new Dog("Jack", 17);
d1.Bark("Yip", 4);

You can break a statement into as many lines as you like in your source code, as long as you don’t insert a line break in the middle of an identifier. The code fragment below splits the two statements above into several lines.

            Dog d1
                = new Dog(
                    "Jack",    // Name
                    17);       // Age
            d1.Bark(
                "Yip",     // Bark sound
                4);        // # times to bark
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: