W2 - Data Types Flashcards
Week 2
What are Data types?
Describes format and size of (i.e. memory occupied) a data item and defines what types of operation can be performed with that item.
What are the types of Data types?
Native and Custom data types.
What does Console.ReadLine() do?
It accepts user input
What is Int type?
This produces a whole number and it’s signed 32-bit integer (int32)
What is Char type?
This is a 16-bit numeric value. A char literal is delimited by a pair of single quotes (‘’).
What is Double type?
Doubles can have a functional part and it’s defined as a 64-bit floating point value.
What is a Decimal type?
A fixed precision number. Uses 128bit storage.
What is a variable in C#
A variable is a storage location in memory with a specific data type that holds a value.
What are the basic data types in C#?
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 do you declare a variable in C#?
A variable is declared by specifying the data type followed by the variable name (e.g., int age;).
What is an assignment statement in C#?
An assignment statement assigns a value to a variable (e.g., age = 25;).
What are constants in C#?
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 do you output data to the console in C#?
The Console.WriteLine() method is used to display text or variables in the console (e.g., Console.WriteLine(“Hello, World!”);).
How do you read input from the user in C#?
The Console.ReadLine() method is used to read input from the user as a string (e.g., string input = Console.ReadLine();).
What is type casting in C#?
Type casting is converting a variable from one data type to another. This can be implicit (automatic) or explicit (manual using a cast).
What is the difference between implicit and explicit casting?
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()).
What is string concatenation in C#?
String concatenation is combining two or more strings using the + operator (e.g., string fullName = firstName + “ “ + lastName;).
What are escape sequences in C#?
Escape sequences are special characters in strings used for formatting, like \n for a new line or " for a quotation mark.
What is the purpose of comments in C#?
Comments are used to add explanatory notes in code and are ignored by the compiler. Single-line comments use //, and multi-line comments use /* */.
What is the difference between WriteLine() and Write() in C#?
Console.WriteLine() writes a line of output and moves to the next line, while Console.Write() writes output without moving to the next line.
What is the Convert class in C# used for?
The Convert class provides methods to convert data from one type to another (e.g., Convert.ToInt32() to convert a string to an integer).
What are arithmetic operators in C#?
Arithmetic operators include + (addition), - (subtraction), * (multiplication), / (division), and % (modulus for remainder).
What is the modulus operator (%) used for in C#?
The modulus operator returns the remainder of a division operation (e.g., 7 % 2 returns 1).
How do you format output in C#?
You can use placeholders with Console.WriteLine() to format output, such as Console.WriteLine(“The result is {0}”, result);.
What are the rules for naming variables in C#?
Variable names must start with a letter, cannot contain spaces, and are case-sensitive. They should be meaningful and follow camelCase or PascalCase conventions.
What is the Parse() method used for in C#?
The Parse() method is used to convert strings to numeric types, such as int.Parse() or double.Parse().
What is the difference between Parse() and TryParse()?
Parse() throws an exception if conversion fails, while TryParse() returns false if conversion is unsuccessful, preventing errors.