Buscar
Estás en modo de exploración. debe iniciar sesión para usar MEMORY

   Inicia sesión para empezar

level: Level 1

Questions and Answers List

level questions: Level 1

QuestionAnswer
How do ref and out keywords work in C#, and how do they relate to Call By Reference?In C#, the ref and out keywords are used to pass arguments by reference, allowing methods to modify the original variable. ref: Requires the variable to be initialized before passing to the method. It allows both reading and modifying the variable inside the method. out: Does not require the variable to be initialized before passing. The method must assign a value to the variable before it returns. Both ref and out enable Call By Reference, allowing methods to modify the caller's original data rather than a copy.
What is a sealed method in C# and when would you use it?A sealed method in C# is a method that cannot be overridden by derived classes. It is used in a class that inherits from a base class to prevent further overrides of a specific method that has already been overridden. You would use a sealed method to ensure the current implementation of the method is preserved and not altered in further subclasses, enhancing security and maintaining consistency in behavior.
What are boxing and unboxing in C#?In C#, boxing is the process of converting a value type (e.g., int, char) to an object type, essentially wrapping the value type in an object. This occurs when a value type is assigned to a variable of type object or any interface it implements. Unboxing is the reverse process, where an object is converted back to a value type. This involves explicitly casting the object back to the original value typ
Have you ever worked with extension methods? If so, can you provide an example from your last project?Yes, I have worked with extension methods. In my last project, I used an extension method to simplify data validation across multiple classes. For example, I created an extension method for the string class to check if a string is a valid email format. This allowed me to call the method directly on string objects throughout the project, improving code readability and reducing duplication.
What is the difference between Call By Value and Call By Reference in C#?In C#, the difference between Call By Value and Call By Reference lies in how arguments are passed to methods: Call By Value: A copy of the variable's value is passed to the method. Changes made to the parameter inside the method do not affect the original variable outside the method. Call By Reference: The reference (address) of the variable is passed to the method using the ref or out keywords. This allows the method to modify the original variable directly, as it operates on the reference rather than a copy.