W2 - Data Types Flashcards

Week 2

1
Q

What are Data types?

A

Describes format and size of (i.e. memory occupied) a data item and defines what types of operation can be performed with that item.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the types of Data types?

A

Native and Custom data types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Console.ReadLine() do?

A

It accepts user input

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Int type?

A

This produces a whole number and it’s signed 32-bit integer (int32)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Char type?

A

This is a 16-bit numeric value. A char literal is delimited by a pair of single quotes (‘’).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Double type?

A

Doubles can have a functional part and it’s defined as a 64-bit floating point value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Decimal type?

A

A fixed precision number. Uses 128bit storage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a variable in C#

A

A variable is a storage location in memory with a specific data type that holds a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the basic data types in C#?

A

The basic data types include:

int: Integer values.
double: Floating-point numbers.
char: Single characters.
string: A sequence of characters.
bool: Boolean values (true or false).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you declare a variable in C#?

A

A variable is declared by specifying the data type followed by the variable name (e.g., int age;).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an assignment statement in C#?

A

An assignment statement assigns a value to a variable (e.g., age = 25;).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are constants in C#?

A

Constants are variables whose values cannot be changed once assigned. They are declared using the const keyword (e.g., const int DAYS_IN_WEEK = 7;).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you output data to the console in C#?

A

The Console.WriteLine() method is used to display text or variables in the console (e.g., Console.WriteLine(“Hello, World!”);).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you read input from the user in C#?

A

The Console.ReadLine() method is used to read input from the user as a string (e.g., string input = Console.ReadLine();).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is type casting in C#?

A

Type casting is converting a variable from one data type to another. This can be implicit (automatic) or explicit (manual using a cast).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the difference between implicit and explicit casting?

A

Implicit casting: Automatically converts smaller types to larger types (e.g., int to double).
Explicit casting: Requires manual conversion, usually with a cast operator (e.g., (int) or Convert.ToInt32()).

17
Q

What is string concatenation in C#?

A

String concatenation is combining two or more strings using the + operator (e.g., string fullName = firstName + “ “ + lastName;).

18
Q

What are escape sequences in C#?

A

Escape sequences are special characters in strings used for formatting, like \n for a new line or " for a quotation mark.

19
Q

What is the purpose of comments in C#?

A

Comments are used to add explanatory notes in code and are ignored by the compiler. Single-line comments use //, and multi-line comments use /* */.

20
Q

What is the difference between WriteLine() and Write() in C#?

A

Console.WriteLine() writes a line of output and moves to the next line, while Console.Write() writes output without moving to the next line.

21
Q

What is the Convert class in C# used for?

A

The Convert class provides methods to convert data from one type to another (e.g., Convert.ToInt32() to convert a string to an integer).

22
Q

What are arithmetic operators in C#?

A

Arithmetic operators include + (addition), - (subtraction), * (multiplication), / (division), and % (modulus for remainder).

23
Q

What is the modulus operator (%) used for in C#?

A

The modulus operator returns the remainder of a division operation (e.g., 7 % 2 returns 1).

24
Q

How do you format output in C#?

A

You can use placeholders with Console.WriteLine() to format output, such as Console.WriteLine(“The result is {0}”, result);.

25
Q

What are the rules for naming variables in C#?

A

Variable names must start with a letter, cannot contain spaces, and are case-sensitive. They should be meaningful and follow camelCase or PascalCase conventions.

26
Q

What is the Parse() method used for in C#?

A

The Parse() method is used to convert strings to numeric types, such as int.Parse() or double.Parse().

27
Q

What is the difference between Parse() and TryParse()?

A

Parse() throws an exception if conversion fails, while TryParse() returns false if conversion is unsuccessful, preventing errors.