Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

Beginning C 7 Hands On The Core

Language Tom Owsiak


Visit to download the full and correct content document:
https://textbookfull.com/product/beginning-c-7-hands-on-the-core-language-tom-owsi
ak/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Beginning C 7 Hands On Advanced Language Features Learn


the advanced level features of C 7 using Visual Studio
2017 Owsiak

https://textbookfull.com/product/beginning-c-7-hands-on-advanced-
language-features-learn-the-advanced-level-features-of-c-7-using-
visual-studio-2017-owsiak/

Learning the Art of Electronics A Hands On Lab Course


Tom Hayes

https://textbookfull.com/product/learning-the-art-of-electronics-
a-hands-on-lab-course-tom-hayes/

Pro C# 7 with .NET and .NET Core Andrew Troelsen

https://textbookfull.com/product/pro-c-7-with-net-and-net-core-
andrew-troelsen/

Beginning PyQt A Hands on Approach to GUI Programming


Willman Joshua M

https://textbookfull.com/product/beginning-pyqt-a-hands-on-
approach-to-gui-programming-willman-joshua-m/
Beginning PyQt A Hands on Approach to GUI Programming
Willman Joshua M

https://textbookfull.com/product/beginning-pyqt-a-hands-on-
approach-to-gui-programming-willman-joshua-m-2/

Beginning C 7 Programming with Visual Studio 2017 1st


Edition Benjamin Perkins

https://textbookfull.com/product/beginning-c-7-programming-with-
visual-studio-2017-1st-edition-benjamin-perkins/

Hands On MQTT Programming with Python Gaston C. Hillar

https://textbookfull.com/product/hands-on-mqtt-programming-with-
python-gaston-c-hillar/

Beginning PyQt: A Hands-on Approach to GUI Programming


1st Edition Joshua Willman

https://textbookfull.com/product/beginning-pyqt-a-hands-on-
approach-to-gui-programming-1st-edition-joshua-willman/

C 7 and NET Core Modern Cross Platform Development 2nd


Edition Mark J. Price

https://textbookfull.com/product/c-7-and-net-core-modern-cross-
platform-development-2nd-edition-mark-j-price/
Contents

1: Why C# and How to Download and Install the Visual Studio Community Edition
b'Chapter 1: Why C# and How to Download and Install the Visual Studio
Community Edition'
b'Locating and downloading the Visual Studio Community edition'
b'Summary'
2: Customizing Visual Studio to Make it Feel More Personal
b'Chapter 2: Customizing Visual Studio to Make it Feel More Personal'
b'Customizing Visual Studio'
b'Selecting the text editor font and size'
b'Selecting the Statement Completion font and size'
b'Selecting the Environment font and size'
b'Positioning Visual Studio panels'
b'Summary'
3: Creating and Running Your First Page
b'Chapter 3: Creating and Running Your First Page'
b'Starting a new project in Visual C#'
b'Working with Solutions Explorer'
b'Adding a document to your browser'
b'Working with HTML code in Visual Studio'
b'Launching the HTML code'
b'Summary'
4: Creating and Running a Page That Incorporates C#
b'Chapter 4: Creating and Running a Page That Incorporates C#'
b'Improving your first program'
b'Working in the Design view'
b'Working in the Source view'
b'Viewing the code in your browser'
b'Summary'
5: Creating and Using a Single Variable
b'Chapter 5: Creating and Using a Single Variable'
b'Setting up Visual C# to deal with a variable'
b'Running the code'
b'Summary'
6: String Interpolation and Updating Visual Studio
b'Chapter 6: String Interpolation and Updating Visual Studio'
b'Selecting a NuGet package'
b'Summary'
7: Formatting Output Strings for More Professional Results
b'Chapter 7: Formatting Output Strings for More Professional Results'
b'Setting a value and formatting it as currency'
b'Summary'
8: Using Variables and Data Types
b'Chapter 8: Using Variables and Data Types'
b'Setting a page title automatically'
b'Summary'
9: Computed Variables and Basic Math
b'Chapter 9: Computed Variables and Basic Math'
b'Declaring and setting two variables to signify two different salaries'
b'Summary'
10: Interacting with Users Through the Web Page
b'Chapter 10: Interacting with Users Through the Web Page'
b'Using Toolbox to search for a command'
b'Summary'
11: Using Method Chaining to Write More Compact Code
b'Chapter 11: Using Method Chaining to Write More Compact Code'
b'Inserting a text box into the markup'
b'Summary'
12: Reacting to a Single Condition with If/Else Blocks
b'Chapter 12: Reacting to a Single Condition with If/Else Blocks'
b'Adding checkbox to your code'
13: Making a Variable Grow by Adding 1
b'Chapter 13: Making a Variable Grow by Adding 1'
b'Growing a variable by one'
b'Summary'
14: Repeating Blocks of Code with While Loops
b'Chapter 14: Repeating Blocks of Code with While Loops'
b'Inserting a button'
b'Summary'
15: Repeating Blocks of Code with For Loops
b'Chapter 15: Repeating Blocks of Code with For Loops'
b'Inserting a button'
b'Summary'
16: Iterating Over Collections with foreach Loops
b'Chapter 16: Iterating Over Collections with foreach Loops'
b'Inserting TextBox'
b'Summary'
17: Examining Multiple Variable Values with Switch Blocks
b'Chapter 17: Examining Multiple Variable Values with Switch Blocks'
b'Inserting DropBox and Label'
b'Summary'
18: Improving Input Processing with TryParse
b'Chapter 18: Improving Input Processing with TryParse'
b'Inserting a button and a textbox'
b'Summary'
19: Replacing If/Else Blocks with the Ternary Operator
b'Chapter 19: Replacing If/Else Blocks with the Ternary Operator'
b'Inserting two text boxes and a button'
b'Summary'
20: Operators That Evaluate and Assign in Place
b'Chapter 20: Operators That Evaluate and Assign in Place'
b'Inserting Button and Label'
b'Summary'
21: Checking Two Conditions with the Logical AND Operator
b'Chapter 21: Checking Two Conditions with the Logical AND Operator'
b'Setting up the project'
b'Summary'
22: Checking Two Conditions with the Logical OR Operator
b'Chapter 22: Checking Two Conditions with the Logical OR Operator'
b'Working with check boxes'
b'Summary'
23: Declaring, Setting, and Reading Arrays
b'Chapter 23: Declaring, Setting, and Reading Arrays'
b'Setting up the basic interface'
b'Summary'
24: Iterating Over Arrays with foreach and for Loops
b'Chapter 24: Iterating Over Arrays with foreach and for Loops'
b'Setting up the beginning interface'
b'Summary'
25: Creating and Using a Simple Method
b'Chapter 25: Creating and Using a Simple Method'
b'Setting up the user interface'
b'Summary'
26: Passing Arrays into Methods
b'Chapter 26: Passing Arrays into Methods'
b'Setting up the user interface' b'Summary'

27: Reference Type and Value Type Variables


b'Chapter 27: Reference Type and Value Type Variables'
b'Setting up the user interface'
b'Summary'
28: Creating More Flexible Methods with the params Keyword
b'Chapter 28: Creating More Flexible Methods with the params Keyword'
b'Designing the starting markup'
b'Summary'
29: Creating More Flexible Functions with the out Keyword
b'Chapter 29: Creating More Flexible Functions with the out Keyword'
b'Setting up the beginning interface'
b'Summary'
30: Combining the ref and out Keywords to Write Flexible Functions
b'Chapter 30: Combining the ref and out Keywords to Write Flexible Functions'
b'Setting up the starting interface'
b'Summary'
31: The out keyword in C# 7
b'Chapter 31: The out keyword in C# 7'
b'Creating the program template'
b'Writing the Summarize function'
b'Implementing the function' b'Running
the program'
32: Multidimensional Arrays
b'Chapter 32: Multidimensional Arrays'
b'Understanding two-dimensional arrays'
b'Summary'
33: Writing Easier Code with the Var and Dynamic Keywords
b'Chapter 33: Writing Easier Code with the Var and Dynamic Keywords'
b'Setting up the project'
b'Summary'
34: Creating a Class with a Constructor and a Function
b'Chapter 34: Creating a Class with a Constructor and a Function'
b'Our initial markup'
b'Summary'
35: Creating a Class with a Static Method
b'Chapter 35: Creating a Class with a Static Method'
b'Setting up a simple initial interface'
b'Summary'
36: Creating a Class with an Object Property
b'Chapter 36: Creating a Class with an Object Property'
b'Setting up a simple markup page'
b'Summary'
37: Creating a Class with Static Fields, Functions, and Properties
b'Chapter 37: Creating a Class with Static Fields, Functions, and Properties'
b'Setting up the interface for this project'
b'Summary'
38: Centralizing Common Code with Inheritance
b'Chapter 38: Centralizing Common Code with Inheritance'
b'Setting up the interface for this lesson'
b'Summary'
39: Centralizing Default Code with Virtual Functions
b'Chapter 39: Centralizing Default Code with Virtual Functions'
b'Setting up a basic HTML for this project'
b'Summary'
40: Model Concepts with Abstract Classes
b'Chapter 40: Model Concepts with Abstract Classes'
b'Introducing the basic HTML for this lesson's project'
b'Summary'
41: Using Custom Types as Return Types
b'Chapter 41: Using Custom Types as Return Types'
b'Setting up the project'
b'Summary'
42: Using Lists to Operate on Data Efficiently
b'Chapter 42: Using Lists to Operate on Data Efficiently'
b'Summarizing the values in a list'
b'Summary'
43: Writing Less Code with Polymorphism
b'Chapter 43: Writing Less Code with Polymorphism'
b'Setting up the markup for this project' b'Summary'

44: Using Interfaces to Express Common Behaviors


b'Chapter 44: Using Interfaces to Express Common Behaviors'
b'Building a hierarchy'
b'Summary'
45: Iterating over Instances with Indexers
b'Chapter 45: Iterating over Instances with Indexers'
b'Setting up a records project'
b'Summary'
46: Building Stabler Apps with Exception Handling
b'Chapter 46: Building Stabler Apps with Exception Handling'
b'Setting up the HTML for this chapter'
b'Using a try block'
b'Summary'
47: Using Named and Optional Parameters
b'Chapter 47: Using Named and Optional Parameters'
b'Setting up the Book class'
b'Summary'
48: Using the Null Coalescing Operator to Write Stabler Applications
b'Chapter 48: Using the Null Coalescing Operator to Write Stabler Applications'
b'Setting up the basic HTML for this project'
b'Searching a database'
b'Summary'
49: Overloading Operators to Perform Custom Operations
b'Chapter 49: Overloading Operators to Perform Custom Operations'
b'Creating a Vector class'
b'Summary'
50: Using Enumerations to Represent Named Constants
b'Chapter 50: Using Enumerations to Represent Named Constants'
b'Setting up a drop-down list'
b'Summary'
51: Creating and Using Namespaces
b'Chapter 51: Creating and Using Namespaces'
b'Creating a new project with a new namespace'
b'Summary'
52: Structs, Random Points, and Sleeping Threads
b'Chapter 52: Structs, Random Points, and Sleeping Threads'
b'Adding a SimpleStruct class file'
b'Coding the struct'
b'Modifying the HTML to make use of the struct' b'Making
an array of points'
b'Displaying the results'
b'Running the program'
b'Debugging the program'
b'Lesson review'
b'Summary'
53: Declaring, Creating, and Using Delegates
b'Chapter 53: Declaring, Creating, and Using Delegates'
b'Setting up the HTML for this project'
b'Checking out the interface'
b'Making a delegate'
b'Running the program'
b'Summary'
54: Switch Blocks with when
b'Chapter 54: Switch Blocks with when'
b'Creating the classes'
b'Writing the Main function code'
b'Running the program'
55: Switch Blocks with Objects in C# 7.0
b'Chapter 55: Switch Blocks with Objects in C# 7.0'
b'Creating the interface'
b'Implementing the interface'
b'Creating the Main() program'
b'Running the program'
56: Tuples
b'Chapter 56: Tuples'
b'Creating the tuple function'
b'Writing the Main() code'
b'Running the program'
57: Local functions in C# 7.0
b'Chapter 57: Local functions in C# 7.0'
b'Creating the application and core functions'
b'Creating the local function'
b'Running the code'
58: Throwing Exceptions
b'Chapter 58: Throwing Exceptions'
b'Creating the main code' b'Running
the program'
Chapter 1. Why C# and How to Download and Install
the Visual Studio Community Edition
If you visit a page like indeed.com and enter C# in the what box, you'll get results that show that
there are many jobs in this field, as shown in Figure 1.1.1. This shows that C# is a very valuable
skill to master. Perhaps you just like to tinker, and C# is great for that as well:

Figure 1.1.1: The many job listings for C# programmers

[1]
Locating and downloading the Visual Studio
Community edition

In this chapter, we're going to take a look at how to get Visual Studio 2017. You can either go
directly to www.visualstudio.com/downloads or just do a search for Visual Studio 2017
download. This should bring you to a page similar to this one:

Figure 2.1: Installing Visual Studio 2017

Keep in mind that these pages are updated regularly. In the preceding screenshot, you will see
that there are several versions. The one that interests us, of course, is Visual Studio Community
2017, the free version.

Click on Free download. This should automatically download a small installer. Depending on how
your system is set up, it will either download it directly to the Downloads folder, or prompt you for
where you want to save it. I've created a VS_Community folder inside my Downloads folder and saved
it there. Of course, you can save it wherever you want to. Once this is done--it won't take long as
it's just a small file--locate the downloaded VS_Community EXE file and open it up.

Once you open it, you should see this screen:

[2]
Figure 2.2: The License screen

Click on Continue, which should take you through to the next screen:

Figure 2.3: Choosing download components

From here, you can select the set of features you want to install on your system. For our
purposes, I've chosen .NET desktop development at the top. If you click on it, you should see a
check mark appear in the top corner to show that it's been selected:

Figure 2.4: Selecting .NET desktop development

[3]
Down at the bottom of the window, there's a location bar. If you click on the three little dots, you
can select where you want the Visual Studio program to be installed on your system. On the
right-hand side, you have a summary field:

Figure 2.5: Selecting the following frameworks

This tells you what's going to be installed; also, down at the bottom, it says Total install size,
3.06 GB, so that's how much minimum free space you need wherever you're going to install this.
Then, of course, click on the Install button in the lower right-hand corner. This should bring you
to a page similar to this one:

[4]
Figure 2.6: Installation in progress

Now, it's just a matter of waiting for everything to be downloaded and then applied to your
system. One thing that I recommend you do at this point is temporarily disable your antivirus
software while this is being installed because it could interfere with the installation process. I got
to about 90 percent and my system hung when I installed it. I went back and disabled my anti-
virus software and it installed fine. You may have to do the same.

Once it's downloaded and installed, you should see a screen similar to this one:

Figure 2.7: The Welcome screen

[5]
From here on, of course, you can either look at the release notes if you want, or just click on
the Launch button. Go ahead and click on the Launch button. This should bring you to a screen
similar to this one:

Figure 2.8: The Sign in screen

If you want, you can sign in with your Microsoft account, if you remember. I chose Not now,
maybe later. The next step is to choose the interface:

[6]
Figure 2.9: Choose color theme

I like the standard Blue one. Of course, you can use the Dark one or the Light one, whichever one
you like, and then click on Start Visual Studio. Once it's loaded, it should look very similar to
the one that you see right here:

[7]
Figure 2.10: Getting Started

Now Go to Help > About Microsoft Visual Studio; you'll see the version that you have installed.
Mine is 15.3.0, which is the latest version at the time of this writing. Make sure that yours is the
same or above (it should be, as you just downloaded the latest version from Microsoft);
otherwise, the code samples that we create will not work because they rely on the features of C#
available in this version. Okay, close the About box. That's it! You're now ready to start learning
C# 7.

[8]
Summary

In this chapter, you learned how to locate, download, install, and launch Visual Studio
Community. In the next chapter, we'll take greater control of Visual Studio and configure it to
some extent.

[9]
Chapter 2. Customizing Visual Studio to Make it Feel
More Personal
In this chapter, we will configure the appearance of Visual Studio a little further.

[10]
Customizing Visual Studio

To get started with customizing Visual Studio, click in the Quick Launch box in the upper right-
hand corner, as shown in the following screenshot. Then, enter a word, such as font, and select
the first item:

Figure 1.2.1: Searching for font settings options

[11]
Selecting the text editor font and size

From here, you can configure many different settings. For example, you can select a Text Editor,
which controls the size of the code in the window so that it's easy to read. The font size should be
something big, such as 20—it makes a real difference; that is, when you are learning, how big
things are makes a difference. They're easier to understand simply because they're bigger. Refer
to the following screenshot to see how this is done:

Figure 1.2.2: Selecting the text editor font and size

[12]
Selecting the Statement Completion font and size

In the next stage, we will customize the Statement Completion settings, as shown in the following
screenshot. This is a very useful feature that makes coding more efficient. Again, set it to
something big:

Figure 1.2.3: Selecting the Statement Completion font and size

[13]
Selecting the Environment font and size

Next, let's configure the Environment fonts. Again, there are many possible options. One that I use
very commonly is Segoe UI. Once more, set it to something big, for example, 18; that is,
something easy to read in any case, as shown in the following screenshot:

Figure 1.2.4: Selecting the Environment font and size

Click on OK when you're finished. Some of these changes take effect immediately and some don't.
For example, as you will see with Environment fonts, the text enlarges immediately.

[14]
Positioning Visual Studio panels

Now, one thing that's useful is being able to position some of the panels. What do I mean by
this? Try the following.

Click on View and then select Solution Explorer—that's a window or a panel. You can position
this panel in many places. If you click where it says Solution Explorer and drag it, you can
liberate this panel and then place it where you like. You are also given a really nice preview of
what to expect once it drops. So, if you drag the Solution Explorer and hover your mouse at the
top box located on the cross, a transparent blue area appears. The blue area tells you that it's
going to go across the top. Again, if you click and drag it to the left-hand side of the screen and
drop it, the Solution Explorer will be positioned on the left-hand side.

Figure 1.2.5: Positioning the Solutions Explorer window

This is how you can control the layout of the panels—just drag them around the screen.
Sometimes, you'll get a cross like the one shown in the preceding screenshot. This simply tells
you that if you hover your mouse over the middle of the cross, the document that you're holding

[15]
with your mouse will be tabbed together with other open windows, like the Start Page in this
example. Now they are basically tabbed as a unit—the Start Page and the Solution Explorer
panel. If you drag it once more and then drop it on the right-hand side, for instance, it will appear
where it is commonly positioned:

Figure 1.2.6: Positioning the Start Page panel

One more useful thing that you can do is enable Auto Hide of panels such as Solutions Explorer.
This means that when you're not using a panel, it hides from view, giving you access to more
space.

If you click on the pin at the top right-hand corner of the panel, as shown in the following
screenshot, you can enable Auto Hide. On the other hand, if you want it back, you click on the
words Solution Explorer that appear vertically below the right-hand side of the screen, and then it
reappears. If you want to pin the panel back to the position you had selected, just click on the pin
again. Now it is back to where you had positioned it, and it will stay there even if you mouse
away from it:

[16]
Figure 1.2.7: Click on the pin at the top right-hand side of the Solutions Explorer window to
enable Auto Hide

[17]
Summary

In this chapter, we reviewed some of the things that you can do to make working Visual Studio
easier.

In the next chapter, we will create a simple C# program and run it.

[18]
Chapter 3. Creating and Running Your First Page
In this chapter, you will create and run a simple first web page. It will contain the minimum that
you need to be able to do work with C# later.

[19]
Starting a new project in Visual C#

To begin, crank up Visual C# and do the following:

1. In the File menu, select New, and then select Web Site.
2. Press Shift + Alt + N.

3. From the New Web Site box, select Visual C# for the language, as shown in the following
screenshot:

Figure 2.1.1: Be sure to select Visual C# as the language, not Visual Basic

4. To keep things as simple as possible, select ASP.Net Empty Web Site.

At the bottom of the dialog box, in the Web location field, the default value File System is
sufficient.

If you wish, click on Browse and save the file to a location you choose and click on OK.

[20]
Working with Solutions Explorer

After you click on OK, you'll see the Solutions Explorer window on the right-hand side of the
screen, as shown in the following code. The Solutions Explorer shows the structure of how
things are designed in Visual C#. You'll notice that there is a Solution; within the Solution, there
is a website, and within the website there are different files that make up the site.

Specifically, Web.config is a file that stores basic website configuration settings. We can see the
following code after we click on the Web.config file:
<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET
application, please visit https://go.microsoft.com/
fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
</configuration>

[21]
Another random document with
no related content on Scribd:
THE REBEL CAMP.
Upon a high plateau, the heavy trees had all been cut away over a
large area. They were designed for the construction of an abattis, and
though nothing had been done beyond chopping down the heavy
timber, the large trunks and limbs, lying in all directions, would have
presented almost insurmountable obstacles to the approach of
cavalry or artillery, had the rifle-pits, just beyond, been filled with
men.
Crossing the rifle-pits, the Unionists were in the enemy’s camp,
though still more than half a mile from the fort. Here were the wall
tents of a regiment, all standing in complete order, with the camp-
fires still blazing, the copper pots of soup for dinner boiling over
them, and the half-made biscuits in the pans. Inside the tents
everything was just as the enemy had left it—pistols, shot-guns,
muskets, bowie-knives, clothing, tables partially set for dinner,
letters half-written, with the ink scarcely dry upon the open page,
cards thrown down in the midst of the game, overcoats, blankets,
trunks, carpet sacks, and so on through all the articles of camp life. It
seemed as if the men were out at guard-mounting, and expected to
return in ten minutes.
Along the river bank were long rows of log barracks, enough to
accommodate two or three thousand men, and finished comfortably.
Inside they bore the same indications that the inmates had
decamped without a moment’s warning.
ADVANCE OF NATIONAL GUNBOATS UP
THE TENNESSEE RIVER.
In accordance with the instructions of Commodore Foote, given
before the attack on Fort Henry, immediately after the capture of the
fort, February 6, the gunboats Conestoga, Lexington and Tyler,
under the command of Lieutenant Phelps, advanced up the river
twenty-five miles, to the crossing of the Bowling Green and Memphis
railway, breaking up a portion of the railway bridge, and rendering it
impassable. They next proceeded to destroy the rebel gunboats and
transports, capturing large quantities of munitions of war and
supplies, and advanced up the river for upwards of two hundred
miles to Eastport, in Mississippi, and Florence, at the foot of Muscle
Shoals, in Alabama, annihilating the rebel flotilla in the Tennessee
river. The expedition was welcomed at every point by the
inhabitants. Twenty-five Tennesseans enlisted at Cerro Gordo, where
also three steamers were seized, containing 250,000 feet of valuable
ship timber.
Toward the latter part of February, intelligence reached Fort
Henry that the rebels were fortifying a point on the Tennessee river,
near the Mississippi State line, whereupon Lieutenant-Commanding
William Gwin, with the gunboats Tyler and Lexington, were sent
forward to reconnoitre the position.
Having learned that the rebels had occupied and were fortifying a
place called Pittsburgh, nine miles above, on the right bank of the
river, he determined to attack them.
At twelve M. the Taylor, followed by the Lexington, Lieutenant-
Commanding Shirk, proceeded up the river. When within twelve
hundred yards of Pittsburgh, they were opened upon by the rebel
batteries, consisting of six or eight field pieces, some rifled. Getting
within one thousand yards, the Taylor and Lexington opened a well-
directed fire, and had the satisfaction of silencing the batteries.
They then proceeded abreast of the place, and, under the cover of
grape and canister, landed two armed boats from each vessel,
containing, besides their crews, a portion of company C, Captain
Thaddeus Phillips, and company K, First-Lieutenant John C. Rider,
of the Thirty-second regiment, Illinois Volunteers (sharpshooters).
Second-master Jason Gondy, commanded the boats of the Taylor,
and Second-master Martin Dunn, commanded the boats of the
Lexington. The landing was successfully accomplished. This small
force drove back the rebels, and held them in check until they had
accomplished their difficult object, which was to discover the real
strength and purpose of the enemy, and to destroy a house in close
proximity to the batteries. In addition to their artillery, the enemy
had a force of not less than two regiments of infantry, and a regiment
of cavalry.

SECTION OF THE MISSISSIPPI RIVER.

SHOWING THE DISTANCES FROM


NEW ORLEANS.
THE BURNSIDE EXPEDITION.

SAILING OF THE FLEET FOR HATTERAS


INLET.
January 12–20, 1862.
Immediately after the departure of the expedition to operate
against Port Royal and the adjacent territory, the organization of
another armament, to proceed to the North Carolina coast, was
commenced, and like its predecessor, was mainly fitted out at
Annapolis, Md., and gradually concentrated at Fortress Monroe.
After many delays, it sailed from that place for its destination on the
12th of January, 1862. The expedition consisted of a large naval force
of light-draught boats, taken from the commercial marine, fitted up
and armed, and a numerous retinue of transports and supply vessels,
all under the command of Commodore L. M. Goldsborough. There
were thirty-one gunboats in the expedition, exclusive of transports,
carrying an aggregate of ninety-four guns. Five of these, called
“floating batteries,” were vessels of strong hulls, heavily braced, and
cut down so as to present but a small surface when in action, and
designed to be anchored during an engagement. The entire number
of vessels of all classes was one hundred and twenty-five.
The land force consisted of about fourteen thousand men, under
the command of Brigadier-General Ambrose E. Burnside, who was
also Commander-in-chief of the expedition. It consisted of fifteen
regiments, divided into three brigades, commanded in their order by
Generals John G. Foster, Jesse L. Reno, and John G. Parke.
The vessels encountered adverse weather immediately after
starting from Fortress Monroe, and a number of the transports were
obliged to put back, having experienced one of those severe storms
which have rendered the coast of Cape Hatteras a terror and a
proverb to the mariner. For a time the expedition was in deadly peril.
Communication between the vessels of the fleet was rendered
impossible, and wreck and disaster appeared to be their inevitable
fate. Several gunboats and vessels were driven ashore and lost, and a
number of valuable lives sacrificed to the fury of the elements, in a
vain endeavor to succor some of the disabled vessels.
Along the whole coast of North Carolina there are many desolate
sand-bars or islands, varying from half a mile to two miles in width,
intersected by numerous inlets, which with few exceptions, are not
navigable. A principal one of these, known as Hatteras Inlet, opening
into the waters of Albemarle Sound, was the point where
Commodore Goldsborough’s fleet was now endeavoring to
concentrate.
On Monday morning, January 13, they were off Hatteras Inlet. Day
broke with a leaden sky, against which the angry, white-crested
waves raced their mad career along the reefs of Cape Hatteras, that
threw its headland oceanward but eight miles distant. Fourteen
steamers were laboring to weather the storm point. Bravely they
breasted on, staggering beneath the giant blows of each successive
sea, the decks swept fore and aft, and all on board reeling from side
to side like drunken men. One figure stood immovable, grasping the
bits and scanning the horizon for traces of ships as they rose on the
glittering mass of foam. It was the square, manly form of General
Burnside, whose anxiety for the fate of his army was intense. Many of
the vessels on which the troops were embarked were nothing more
than huge top-hampered river steamers, with projecting guards, that
would break up like cardboard if fairly struck by a sea.
At dark, all hands on the flag-ship were startled by the report of a
gun, and on reaching the hurricane deck they saw a large brig
drifting rapidly on to the bar. As it grew darker, and her outline
became less defined, the excitement became intense. She was
evidently in a most critical position, and every moment might be her
last. Slowly the black hull rose and fell, each time gliding nearer and
nearer to the vortex of white breakers, which, once reached, nothing
could save her. Suddenly a fringe of musketry fire surrounded her
bulwarks, and blue-lights were burnt in her tops. Volley after volley
succeeded each other in rapid succession, yet apparently no one
could help her; no human power dared face the tempest, and,
perhaps, share her doom. General Burnside boarded every steamtug
in the harbor; offered any reward, and also to go himself in aid of the
brig, but all held back. Were three hundred men to be launched into
eternity, and no effort made to save them? At last one brave seaman
volunteered to take his little steamer out—General Burnside jumped
aboard her—but by the earnest entreaties of the officers he delegated
the honorable position to one of his staff, for his heroic conduct had
nerved every brave heart in his command.
BURNSIDE’S FLEET AT HATTERAS INLET.
From the 13th of January until the 4th of February, the fleet at
Hatteras Inlet experienced an almost uninterrupted series of gales,
and the two dykes which reach the east and west boundaries of the
inlet, were fringed with perpetual spray and foam from the breakers.
The lighter vessels, comprising the propeller gunboats, the side-
wheel steamers, and most of the schooner transports, had gone
safely through the “Swash,” and were securely anchored some two
miles from the throat of the inlet, while the larger ships and barks
were still riding outside, with colors continually flying for a pilot.
Many of these vessels were crowded with men suffering for the
want of necessary supplies, especially water, and the largest of the
transports had a draught of from two to four feet more than the
specifications of the guarantee should have allowed. The
consequence was, that they grounded in attempting the passage. An
occasional cessation of a few hours in the storm afforded opportunity
that could be taken advantage of by vessels to try the dangerous
passage, aided by the tugs, that responded but shyly to the signals for
aid. And thus for days the severity of the gale defied all
communication between the vessels outside of the bar, as they
battled with a fiercer foe than that upon the land—fighting a very
hand-to-hand fight with storm and ocean.
Nearly three weeks passed before all the vessels of the expedition
were brought in safety through the swash to anchorage within the
inlet. Though the severity of the storm had threatened the
destruction of the entire armada, and occasioned the deepest gloom
and anxiety in the minds of thousands of loyal friends at home, the
brave and skillful commanders were never despondent, and met the
new dangers of each day with hopeful energy and perseverance.
Eight vessels of various sizes were cast away or foundered in the
storm, though but few lives were lost.
Colonel J. W. Allen and Surgeon T. S. Weller, of the Ninth New
Jersey, were drowned from a small boat while on a noble mission to
relieve a suffering crew.
Many of the large transports were grounded in attempting to pass
inside the inlet. From the necessity of lightening them, vast
quantities of property were lost or thrown overboard. An expedition
beset with such difficulties, all overcome by indomitable
perseverance, has seldom been recorded in the history of any
country.
CAPTURE OF ROANOKE ISLAND.

February 8, 1862.

After a detention of three weeks in sight of Hatteras Inlet,


occasioned by the severity of the storm, and the difficulty of piloting
the heavily-laden vessels through the inlet, the expedition received
sailing orders on the 4th of February, and proceeded on the next day
to the point of attack. The fleet anchored on the night of February 5,
about ten miles below the southern point of Roanoke Island, from
whence they again weighed anchor at eight o’clock on the morning of
the 6th. A storm retarded their progress, and they remained over
night without passing through Roanoke Inlet to Croatan Sound.
At ten o’clock on the morning of the 7th, the gunboats, under the
lead of the Flag-officer’s ship, moved forward, and were soon inside
the narrow passage leading into Croatan Sound, known as Roanoke
Inlet. The mainland juts eastward, forming a point of marshy land at
the southern extremity of Croatan Sound, which is the only navigable
water leading past Roanoke Island. A small island forms the eastern
boundary of the channel, while the western shore is a low marshy
point. Following Commodore Goldsborough’s squadron were the
gunboats of the coast division, all of which passed through without
interruption.
The S. R. Spaulding, with General Burnside on board, next passed
through, but the remainder of the transports were detained about
two hours. The rebel gunboats could now be seen close in shore,
evidently under the guns of batteries on shore. As the fleet passed
into the sound, a signal was fired from one of the rebel gunboats, to
announce its approach. This was about half-past ten o’clock. At half-
past eleven the first gun was fired from the flag-ship, and was replied
to by the rebels. The Flag-officer hoisted the signal: “This day our
country expects that every man will do his duty.” The effect was
electric. The men worked their guns with unflagging energy,
determined that their country should have nothing to complain of in
relation to them. As the Federal vessels came within shorter range,
the fire became more rapid, but the regular fire did not commence
until noon, when the flag-ship displayed the signal for close action.
The number of the rebel gunboats visible in the early part of the
engagement was seven. As the vessels came into closer action, they
moved to the northward, with the design of drawing the Union fleet
after them, and bring them under the guns of their batteries on the
island. At twelve o’clock the engagement became general, between
the retreating gunboats of the rebels and the Union fleet, varied by
an occasional shot from a battery on shore. The firing was
exceedingly brisk for some time, but the distance was evidently too
great for destructive effect. The one hundred-pound Parrott gun on
board the Southfield, to which the Flag-Officer transferred his flag,
boomed forth terrific explosions, followed by the roar and crash of
flying shells. The puff of smoke in the air was almost simultaneous
with the splash of fragments in the water. The rebel gunboats kept up
a steady fire in reply. Their fire was varied at times by the louder
report of a hundred-pound Parrott gun on board one of their vessels.
The Sawyer gun on board the Fanny, which was captured by the
enemy at Hatteras Inlet, was the most annoying in its effects, as the
range was long and very accurate.
The fire from the fort indicated a weak force working the guns. The
rebel gunboats retired steadily a considerable distance up the sound.
A line of piles driven into the bed across the principal channel,
obstructed the progress of the Union vessels in the pursuit of the
retreating rebels, who occupied an inner channel under the guns of
their battery. The Union fleet now turned their attention to the fort,
which kept up a steady and rapid fire.
On the afternoon of the 7th, the transports, with the land forces,
were all brought safely through Roanoke Inlet, and clustered securely
in rear of the bombarding fleet. General Burnside gave immediate
orders for landing the forces, which was done at a small cove, known
as Ashby’s Harbor. In less than an hour four thousand men were
landed, and by eleven at night, the entire force, excepting one
regiment, were on the island, and their bivouac-fires lighted up the
shore and the woods for the distance of a mile.
At nine o’clock on the morning of the 8th, a few shots were
exchanged between the Federal gunboats and the battery, which
ceased after fifteen minutes’ duration, and was not renewed during
the day. The rebel gunboats had retreated, and all interest now
centered in the movements of the land forces.
From definite information received by General Burnside, the
position of all the works on the island was clearly known, and his
movements were based on this knowledge. The plan of attack
consisted of a central attacking column, led by Brigadier-General
Foster; a left flanking column to attack the right of the enemy’s work,
under Brigadier-General Reno, and a right flank column to attack the
left of the enemy’s position, under the command of Brigadier-
General Parke.
The approach to the enemy’s position was through a swampy
wood, with a dense undergrowth, rendering it almost impenetrable.
An ordinary cart-road leading through this wood from the shore to
the fieldwork, a distance of about a mile, was the only mode of
communication. The woods in front of the battery had been cut down
a distance of three hundred yards, forming an open space to be
played on by the rebel guns, about two hundred feet wide. The woods
immediately in rear of the work were also cut down to permit the
manœuvreing of their own forces.
Their battery consisted of an earthwork with three faces covering
the open space before, and the woods at each side of the open space,
but with a general direction of fire to the front. The guns were
mounted in embrasure, and consisted of a twenty-four-pounder
brass Dahlgren howitzer, a long eighteen-pounder brass field-gun,
and a twelve-pounder brass field piece. In front of the work was a
ditch eight feet wide and about three feet deep, filled with water. The
earthwork was about thirty-five yards wide, and was erected across
the road. The ground in front of the work was a deep marsh, on
which the trees which were felled still lay. The difficult nature of this
ground was increased by the pits from which the turf and earth for
the fieldwork had been taken. Branches were strewn over the front of
the work, making it impossible to discover it from the wood in front.
The defending force consisted of about three hundred men, within
the breastwork, and about two thousand as a reserve, partly deployed
as skirmishers on the left of the battery. The rebels relied chiefly for
the defence of their flanks on the almost impenetrable nature of the
wood on each side. Their entire force, with the exception of the force
working the battery, was scattered in front and in the woods on the
left as skirmishers.
The Federal army advanced from the bivouac-ground of the
evening previous, where they had spent the night with nothing but
thin overcoats to protect them from a cold, driving rain. They had left
their knapsacks and blankets on the transports, each man carrying
nothing but his haversack, with three days’ provisions, and his
cartridge-box, with forty rounds of ball-cartridge. The centre, under
the command of General Foster, was composed of the Twenty-fifth
Massachusetts, Colonel Upton; Twenty-third Massachusetts, Colonel
Kurtz; Twenty-seventh Massachusetts, Colonel Lee, and the Tenth
Connecticut, Colonel Russell, and moved forward about eight o’clock.
They were followed by the second column, under General Reno,
consisting of the Twenty-first Massachusetts, Lieutenant-Colonel
Maggi; the Fifty-first New York, (Shepard Rifles,) Colonel Ferrero;
Ninth New Jersey, and the Fifty-first Pennsylvania, Colonel Hartraaf.
The third column, led by General Parke, was formed of the Fourth
Rhode Island, Colonel Rodman; First battalion, Fifth Rhode Island,
Major Wright; and Ninth New York, Colonel Hawkins.
A brilliant, well contested fight of two hours’ duration put the
Federal forces in possession of Roanoke Island, with all the batteries,
mounting thirty guns, and Fort Forrest, on the mainland, mounting
eight guns. It resulted in the unconditional surrender of the rebel
army on the island, numbering 2,500 men, with all their arms and
munitions of war. Captain O. Jennings Wise, son of ex-Governor
Wise of Virginia, lost his life in this engagement. The Governor
himself, being absent from his command on the day of battle,
escaped.
Colonel Russell, of the Tenth Connecticut, and Lieutenant-Colonel
De Monteuil, of the New York Fifty-third, were killed.
The Federal loss was fifty killed and one hundred and fifty
wounded. That of the rebels was about twenty killed, and sixty
wounded.
EVACUATION OF BOWLING GREEN, KY.

February 14–16, 1862.

Before the commencement of hostilities in the State of Kentucky,


the rebel General Buckner, Commander-in-Chief of the State militia,
seized upon the town of Bowling Green, in Warren county, in the
southern section of the State, and occupied it as the grand centre and
depot of future military operations. The position was well chosen. It
was situated on the line of the Louisville and Nashville railway, and
connected also by rail with Memphis and Nashville; while water
communication through the Barren river was open to the Green
river, the Ohio, and Mississippi, and thus to all important points.
As a military post, its means of defence were also of the first
importance. The town lies on the south bank of Barren river, at a
point where the channel makes a bend not unlike a horse-shoe. The
buildings are situated a distance of five hundred yards from the
banks, which rise by jutted rocky sides fifty feet from the water level.
A series of nine swelling hills, or knolls, completely encompass the
town on the land side, and on these Buckner had erected a cordon of
forts; some of stone, and others of earth, twenty feet in thickness—all
of great magnitude. Forty-nine guns were mounted on the various
fortifications, and great engineering skill had been displayed in their
construction.
On learning the defeat of Zollicoffer’s troops at Mill Spring, on the
19th of January, General A. S. Johnson, on the 25th, ordered the
evacuation of Bowling Green, and General Floyd’s brigade
immediately marched from thence to Fort Donelson. Active
measures were then taken to carry out the order further, by shipping
heavy ordnance to Columbus, which place General Grant’s
reconnoissance at that time had induced the Confederates to believe
would be the first point of attack from the Federal army.
After the capture of Fort Henry, on the 6th of February, by which
the enemy’s communication with Columbus was intercepted, the
remaining troops were distributed, some to Fort Donelson, some to
Nashville and other points; and a work of indiscriminate destruction
of the buildings and property in the town commenced. The beautiful
iron railway bridge, and the wooden turnpike bridge over the Barren
river were first destroyed. The railway bridge over the Green river,
some forty miles to the north-east, had long since been burned, and
the forces of General Buell had been deterred from crossing that
stream up to the present time.
On the 11th of February, however, General Mitchell’s division,
encamped on Bacon creek, seven miles north of the Green river, were
ordered to advance on Bowling Green, and on that day marched to
Camp Madison, one mile north of the river; where receiving
confirmatory information of the retreat of the rebel forces, they
hastened forward.
Thursday morning, February 13th, the division—infantry, cavalry,
and artillery, left Camp Madison for Bowling Green, forty-two miles
distant, and made twenty miles the first day. The railroad appeared
to be but little injured, but all the buildings were destroyed. The
roads the first day were in splendid order, but much obstructed by
trees, which were, however, speedily removed by two companies of
mechanics and engineers, who swung their axes with energy, and
were never delayed over fifteen minutes by any impediment. The
ponds along the road were filled with dead horses and cattle, so long
as any cattle were to be found to fill them. The troops rested at noon
at Cave City, which was very nearly destroyed. On the second day
they started again for Bowling Green. The next morning was cold,
with about an inch and a half of snow, but they were up betimes and
on their way, the Nineteenth Illinois ahead as usual, with her blue
flag waving triumphantly. The road was obstructed, and filled with
signs of the rapid retreat of Hindman’s forces.
Hearing repeatedly that the railroad bridge over Barren river was
destroyed, and that the Confederates would not stand this side of the
river, Colonel Turchin ordered the cavalry and one battery ahead.
The ranks opened to the right and left, and Captain Loomis’ battery
dashed by in fine style toward Bowling Green. The men hearing the
cannon roar, hurried on, and reached the banks of the river opposite
Bowling Green, about two o’clock, making the forty-two miles in
about thirty-seven hours. After the firing commenced they seized
every team along the road, and had the knapsacks drawn by horses
the rest of the way, much to the relief of tired shoulders. General
Turchin fired the first shell into the town, and immediately three
regiments were seen scampering to the cars, and putting off in great
confusion.
But though within a mile of Bowling Green, they were powerless to
interfere, for there was Barren river, wide and unfordable, between
them, and both bridges destroyed. The Texan Rangers soon began to
fire all the public buildings. Fifty men under Captain Scott, got ready
to cross in a little skiff by parties, and try to drive out the few who
remained to perform this work, but the General would not allow it.
They then pitched their tents and prepared to wait until a bridge
could be erected. When snugly tucked in their blankets, the assembly
beat to arms, and the brigade was soon in ranks. They expected to
march to town, but were put on the back track some three miles.
They left the main road, and soon came to the river, where they
built fires and rested as well as possible. Here the repairs of an old
wherry were completed, and they crossed the river, protected by
artillery. There was a slight snow falling, and it was uncomfortably
cold. The Nineteenth and Twenty-fourth, Hecker’s Illinois, crossed
first. The men suffered intensely from cold, but declared that they
had rather be shot than frozen, and pushed on. But no enemy
appeared, and the tired soldiers soon surrounded the fires, some of
which had been burning for several days. All the public buildings and
several warehouses, filled with pork, beef, coffee, etc., were
destroyed. A pile of grain thirty feet by twenty, was burning when the
Federal troops arrived. Four engines and several cars were also
burnt. The cars had been carrying away provision for a week, but still
immense quantities were destroyed. Boxes of guns, large numbers of
bowie-knives roughly fashioned of iron, every conceivable kind of
shooting apparatus, and all sorts of hardware for cooking and other
uses were found in immense quantities.
Bowling Green is a town of considerable commercial importance,
and possesses many large stores and warehouses. The majority of the
inhabitants were loyal in their sentiments, though many influential
citizens sympathized with the rebellion; but when the work of
destruction commenced, no discrimination was allowed, and all were
made sufferers. The unexpected arrival of General Mitchell’s army,
and the terror of his artillery, drove the rebels from the town before
their incendiary intentions were fully consummated, and much
private property was saved which would else have been consumed by
the flames.
When General Buckner was exercising military sovereignty in
southern Kentucky, one of his proclamations demanded that every
man in Wright county should deliver to him at his headquarters, one
gun, or twenty dollars in money, under the penalty of fifty dollars’
fine, or ninety days’ imprisonment. In response to this edict, a
motley collection of old squirrel and shot-guns were added to the
Confederate stores, and with other treasures were packed in
buildings at Bowling Green. A hasty evacuation of that stronghold
having become a “military necessity,” these buildings were fired by
the retreating rebels, and among the ruins which met the curious
gaze of General Mitchell’s men when they entered the town, were
scattered piles of the iron parts of these guns, in several places a foot
thick.
CAPTURE OF FORT DONELSON.

February 13–16, 1862.

Bravely as the army of the West had sustained the honor of the
Union, the crowning glory of taking Fort Donelson remained to be
accomplished. To attack a strongly-defended fort, formidable by
nature and rendered almost impregnable by military art, was a work
of extreme danger, nay, of impossibility to less resolute men.

ATTACK ON FORT DONELSON BY THE FEDERAL GUNBOATS.


THE SURRENDER OF FORT DONELSON.

The relative positions of Fort Henry and Donelson, the former on


the Tennessee river and the latter on the Cumberland, should be
clearly understood, in order to comprehend the difficulties of this
undertaking.
Fort Henry had been occupied by Federal troops, and it became
necessary to effect the reduction of Fort Donelson, in order to open
the river to the navigation of the national flotilla, and to reach
Nashville, the capital of Tennessee.
The surrender of Fort Henry took place on the 6th of February.
One of the gunboats, the Essex, being disabled, was obliged to return
to Cairo for repairs, while the Lexington, Conestoga and Tyler,
returned to the Ohio, in order to reach the Cumberland river to make
the ascent to Fort Donelson. Commodore Foote having completed
his preparations, left Cairo on the 11th of February for the scene of
action—the Carondelet having previously been sent forward to
reconnoitre the position.
On the same day General Grant issued his orders for the
movement of the land forces in two divisions, on the following
morning. The distance from Fort Henry to Fort Donelson across the
land lying between the two rivers, is fourteen miles. There are several
roads running from Fort Henry to Dover, near which Fort Donelson
was situated. The divisions were disposed by brigades, one of which
was to be thrown into Dover to cut off the retreat of the enemy, if
attempted by that route.
Fort Donelson takes its name from Andrew Jackson Donelson, a
citizen of Tennessee, and its construction was commenced as early as
May, 1861. It occupied the best position for defence on the
Cumberland river, standing on the summit of a fine slope, rising to
the height of one hundred and fifty feet from the river, on its right
bank, and mounted sixteen guns. There were two water batteries,
one of which was about twenty or thirty feet above the river, and
defended by nine pieces, eight thirty-two-pound guns, and one ten-
inch columbiad. The second was some sixty feet above, and was
mounted with one ten-inch columbiad, and two thirty-two pound
carronades.
Both these batteries were sunken or excavated in the hill-side. In
the lower one, strong traverses were left between the guns, to secure
them against an enfilading fire. The elevation above the water at the
time of the gunboat attack, gave them a fine command of the river,
and made the task of attacking them in front an arduous one. The
range of the guns in arc, was, however, quite limited.
The third occupied the summit of the hill, and mounted four 128-
pound guns. The camp was behind the fort on the hill, but within
range of gunboats on the river.
THE NAVAL ATTACK.
On the night of February 11th, the St. Louis, (the flag-ship,)
Louisville, and Pittsburg, sailed from Cairo. The Carondelet, as
already stated, had been dispatched a day or two in advance, and at
Paducah, on the noon of the 12th, the fleet was joined by the
Conestoga and Tyler. Of these the three first were iron-clad vessels.
From Paducah the fleet was accompanied by sixteen transports,
carrying six thousand infantry, and cavalry and artillery.
The fleet followed the flag-ship of Commodore Foote, as they
turned out of the Ohio, and began the ascent of the Cumberland.
Passing onward from the Ohio, sweeping through Kentucky and
Tennessee up to the western boundaries of Virginia, the fleet carried
the national ensign, which was met with continual cheers and
responses from the people on the banks.
About four o’clock in the afternoon, a messenger steamer, the Alps,
met the fleet, with a dispatch from General Grant, requesting all
haste to be made, as the gunboats were anxiously expected. Putting
on steam, the Alps took the St. Louis and Louisville in tow, leaving
the transports to hasten as rapidly as they could be urged. The
former arrived within two miles of the fort at twelve o’clock, on the
night of Thursday, the 13th.
On the morning of that day, the Carondelet, by order of General
Grant, had bombarded the fort, and single-handed, commenced the
attack on the works. On the previous day she had advanced and fired
eight shots, but without drawing out any reply. The attack of the 13th
was differently met by the fort, as the shells were briskly responded
to, and a vigorous fire was maintained for two hours. The Carondelet
kept her bows hard on the fort, carefully guarding against presenting
her broadside to the enemy. She fired one hundred and twenty-eight
shots in ninety-five minutes. At the end of that time, a ball from one
of the 128-pound guns entered her port-bow, and struck a portion of
her machinery. Six men were slightly wounded by the splinters which
flew from the ship’s timbers. She retired beyond the range of the
guns, to ascertain the amount of damage, and in the afternoon, after
repairing, was again ordered to the charge, and fired a number of
shots, but without sensible effect.

You might also like