Home
Username:
Password:
Introduction to Microsoft C# 2008 Tutorials

C# Essentials / Strings

Subtitles of the Movie

Now let's take a look at strings. Now, you've probably noticed, if you've been watching some of the other videos, that I've talked about data types, value types, reference types, that I've talked about bytes and integers and longs and decimals and I've kind of been avoiding the topic of strings and so let's talk about strings now. Now, as it turns out, a string is simply a string, no pun intended, but a group of letters, numbers, characters and basically you generally think of them as alpha characters for the most part. But they can also be numbers as well. And let me show you just how to declare a basic string variable. Notice I can just say String A equals to or is equal to Mark and that's pretty straightforward and now String A equals the word Mark. Now, a couple of things you need to know about strings. First of all, strings are actually a reference type in C# and a string is actually created from a class that exists, a string class. It is an object in the .NET Framework and so there's some things happening in the background with strings that make it kind of interesting and I won't get into all those right now. It's a little more advanced but for the most part what I want to go through here is some of the things you can do with strings and then we'll talk about converting strings to use them to report out and combine them with numbers and so forth the way you'll normally use them in the real world in the next video. But for now I just want to show you a couple of things. First of all, this is the way that we're going to create a Variable A with a data type of string and load it with some string data. We can also load a string empty if we would like simply by putting just two quotes and we can also put null there and it does the same thing. Now, we can also join or concatenate strings so if I go back and if I put the word long in there now, I have String A as Mark and B is long and then I can concatenate. Now, let's do string name equal to Mark. Then I can use the Plus Sign in C# to concatenate. Then I'll put a space in there and I will concatenate that and then that will give me a string that's Mark, a space and long all together. And there's a lot of things that I can do with strings but there's going to be a lot of times when you try to work with strings and with numbers and it'll throw errors at you and it'll tell you I can't convert that to an integer, I can't convert an integer to a string and it'll kind of drive you nuts. And so all I wanted to show you here in this video is how to create string variables to hold our strings and then in the next video, which is entitled Converting, I'm going to use these strings to show you how we're going to convert integers to strings and strings to integers and so forth and actually use them the way you'd normally use them in your program. For now we'll stop right here on the strings; very simple, very straightforward. The big thing here of course is concatenate and so join me in the video on converting and let's talk about some really cool things that we can do with these things.

Tutorial Information

Course: Introduction to Microsoft C# 2008
Author: Mark Long
SKU: 34046
ISBN: 1-935320-78-5
Release Date: 2009-10-09
Duration: 7 hrs / 76 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available