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

C# Essentials / C# Variables

Subtitles of the Movie

OK, let's talk about creating variable in C# and this is going to be kind of a short video. I'm going to show you real quickly how we're going to create a variable, really straightforward and let's just get to it. What I've done here is I've opened the solution that we created in some of the earlier videos, so you might want to go back and watch some. I think it was your first C# program and commenting your code and those things. But we're going to use that same solution and if you'll just open Visual Studio 2008 and open the VTC Class Solution. If you open Visual Studio and you can't see it, just do File, Open, go to Project on your VTC Class Folder and open the SLM file and that'll do it. It should bring you here. Now notice, I have taken out some of the comments and I think I'd put in a function and stuff so clear everything off, get your screen just like you see it right here and inside the Click Event on the Click Button, that button that we put on our form, I am going to show you here, first of all the syntax that we use to create variables in C#. The first thing we're going to do is put the actual data type that we want the variable to be so we'll put that in there and then we actually put the variable name that we want to use. Then if we want to go ahead and set this variable to a value, we can put an equal sign and we can put it in there. So in this instance I would have been creating something to hold the number and that's the way it would look. So let's look at how this looks in real life. I'm creating an integer data type. I put int and then I put X, OK and then I set it equal to three and it's that simple and I just created a variable. And so then I can use that variable however I would like, OK? Then I can create another variable int Y equals four, right? And then I can do int C equals and I'll put zero in there and then of course I can go back now and say C equals X plus Y and then I can start to use these things and I can use these wherever I would like. So very simple to set these up. Always put the data type, then the actual name of the variable and then you can go ahead and set it. Now, if I didn't want to set it, I could just do this and that will create the variable and then when I want to set it equal to a value I can do that later. Very easy to create variables here. That's how you do it. As we go through the next few videos we'll talk about some things like scope, expression, statements, casting and all sorts of things, show you how to actually use some of these variables in a program. So I'll see you there.

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