C# Tutorial Part 3.2 – Variables Questions

This is the third part of the third part my C# tutorial – some optional questions about variables to help your understanding of this section. You can choose to skip them if you so wish.

1) Rearrange the following code into one line:

int counter;
counter = 12;

2) Rearrange the following code into one line:

int counter, other;
counter = 12;
int myint = 10;
other = 5;

HINT: You can declare multiple variables on one line by putting commas between each declaration and the semi colon after the last one

3) What does the assignment operator look like?

4) What is ‘int’ short for?

5) Can a signed variable hold negative values?

6) Which type is signed: short or ushort?

7) Which type can hold your name: bool or string?

8 ) What is wrong with the following code?

string myname = Hi it’s Matt!;

9) What colour do strings turn when they are typed? (in Microsoft Visual C# 2010)

10) What is wrong with the following code?

string number1 = 5, number2 = 3;
int answer = number1 + number2;

1) int counter = 12;
2) int counter = 12, other = 5, myint = 10;
3) =
4) Integer
5) Yes
6) short
7) string
8 ) The value I was trying to assign to the string I had just created wasn’t a string value because it wasn’t in double quotes. It wasn’t the name of another string variable because it had a space and an exclamation mark
9) Red
10) a) You can’t add together numbers in strings because they count as text. b) You can’t assign two strings added together to an integer variable

Part 4.0 will be about operators


About Matt

I like writing, filmmaking, programming and gaming, and prefer creating media to consuming it. On the topic of consumption, I'm also a big fan of eating.
This entry was posted in Programming and tagged , , , , , , . Bookmark the permalink.

Enter comment:

Please log in using one of these methods to post your comment:

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