Variables and Data Types in C#
Preguntas 10
Las respuestas correctas se muestran a los docentes que han iniciado sesión.
-
Value type default
What is the default value of an uninitialized local variable of type int in C# when it is read after being declared but before being assigned?
undefined
-1
0
null
Think about how the compiler treats local variables: it refuses to let you read them unless they are definitely assigned, so consider what value a field of this type would get by default. -
Implicit conversion
Which of the following conversions is performed implicitly by the C# compiler without requiring an explicit cast?
Assigning a string to an int variable
Assigning a long value to an int variable
Assigning an int value to a double variable
Assigning a double value to an int variable
Consider which conversion can never lose information, because the range and precision of the target type fully contain the source values. -
-
-
var keyword
Which statement about the var keyword in C# is correct?
var is only allowed for reference types such as string
var variables can be declared without any initial value
var makes a variable dynamically typed, so its type can change at run time
The compiler infers the static type of a var variable from its initializer at compile time
Focus on when the type is determined: is it decided while the program runs, or while the code is compiled from the right-hand side of the declaration? -
-
Parsing and value types
Which C# code correctly converts the string "123" to an int and stores it in a variable named number, using a method that is designed for parsing text?
int number = Convert.ToString("123");
int number = (string)"123";
int number = "123".ToInt();
int number = int.Parse("123");
Look for the static method on the int type whose purpose is to read a number from a string. -
Value types and reference types
In C#, the int data type is a value type, which means a variable of type int stores its actual value directly rather than a reference to the value.
True
False
Think about where the data itself is kept for simple numeric types such as int, compared with objects created with new. -
-
Acerca de
- Materias
- c#
- Etiquetas
- Añadido por IA variables Añadido por IA data types Añadido por IA type conversion Añadido por IA value types Añadido por IA explicit casting
- Público
- Escuela secundaria · Grados 10–12
- Dificultad
- 6 de 10
- Idioma
- Inglés
- Quién puede verlo
- Todo el mundo
- Completado por IA
- Lo marcado con un destello lo añadió la IA.
- Escrito por IA
- Claude Haiku 5.5
- Creado
Comentarios