C# Certification Flashcards
70-483 Certification Exam Review (892 cards)
Suppose you are developing an application which stores a user’s browser history. Which collection class will help to retrieve information of the last visited page?
Last visited (LIFO= Stack)
Answer = Stack
The following code is boxed into object o.
double d = 34.5;
object o = d;
You are asked to cast “object o” into “int”.
The object needs to be cast to double
Because it is a decimal value need to cast to float
Finally cast to int
Answer = int i = (int)(float)(double)o;
You are developing a game that allows players to collect from 0 through 1000 coins. You are creating a method that will be used in the game. The method includes the following code. (Line numbers are included for reference only)
01 public string FormatCoins(string name, int coins)
02 {
03
04 }
The method must meet he following requirements:
- Return a string that includes the player name and the number of coins
- Display the number of coins without leading zeros if the number is 1 or greater
- Display the number of coins as a single 0 if the number is zero
You need to ensure that the method meets the requirements. Which code segment should you insert at line 03
Format specifier D formats integer digits with optional negative sign.
Answer = string.Format($”Player {name}, collected {coins:D3} coins”);
How do you encapsulate an array of integers into an indexer?
private int[] array;
public int this[int index] { get {return array[index];} set { array[index] = value;} }
Is the following method “Display” considered to be overloaded?
class Person { public void Display() { }
public int Display()
{
}
}
No
Overloading refers to different parameter types. The display method has different return types.
Suppose you’re creating a class named Player. The class exposes a string property named HitSpeed. Here is the code snippet of player class.
01 class Player 02 { 03 public int HitSpeed 04 { 05 get; 06 set; 07 } 08 }
The HitSpeed property must meet the following requirements:
- The value must be accessed by code within the Player class
- The value must be accessed to derived classes of Player
- The value must be modified only by code within the Player class.
You need to ensure that the implementation of the EmployeeType property meets the requirements. Which code segment you should replace at line 05, and 06?
protected get;
private set;
Suppose you are developing an application. The application has two classes named Player and Person.
The Player class must meet the following requirements
- It must inherit from the Person class
- It must not be inheritable by other classes in the application.
Which code segment should you use?
sealed class Player : Person {
}
Suppose you are developing an application that includes the following code segment.
interface ICricket { void Play(); }
interface IFootball
{
}
You need to implement both Play() methods in a derived class named Player that uses the Play() method of each interface.
class Player : ICricket, IFootball { // Both ICricket and IFootball have play methods // Must be declared explicitly void ICricket.Play() { } void IFootball.Play() { } }
Player player = new Player();
( (ICricket)player ).Play();
( (IFootball)player).Play();
Which type cannot be instantiated? A enum type B static type C class type D System.Object type
B. Static type
Which operator is used to get instance data inside type definition?
this
What is the code segment for defining implicit type conversion for a Person class?
class Person { public string name; public int age;
public static implicit operator Person(string n)
{
Person person = new Person{age=0, name=n};
return person;
}
Which operator is used to compare types?
A) as
B) is
C) this
D) ?
B) is
Suppose you are developing an application that saves age values in integers
int age = 22;
You are asked to provide the right code snippet for defining the extension method for age.
static class Extension { public static void ExtensionMethod(this int i) {
}
}
Which jump statement will you use to start the next iteration while skipping the current iteration of loop?
Continue
You need to use null-coalescing operator to make sue “name” variable must have a value not null.
What is the right way to use null-coalescing operator in C#?
string name = n??”No Name”;
You are developing an application that saves user’s information. The application includes the following code segment (line numbers included for reference).
01 public bool IsNull(string name)
02 {
03 return true;
04 }
You need to evaluate whether a name is null
What code segment should be inserted at line 03.
I would do this….
return string.IsNullOrWhiteSpace(name) ? false: true;
or
return name==null?false: true;
Suppose you are implementing a method name “Show” that will be able to take an unlimited number of int arguments. How are you going to define its method signature.
void Show(params int[] arg)
Which of the following methods help us to convert string type data into integers?
Select any two
A) Convert.toInt32();
B) Convert.Int32();
C) int.parse();
D) parse.int();
A) Convert.toInt32()
C) int.parse()
What collections stores values in Key, Value pairs?
Dictionary
SortedList
HashTable
To control how objects are compared, what interface is implemented
IComparable
Last In, First Out data structures are represented as?
Stack
First In, First Out structures are represented as?
Queue
When are generic collection classes appropriate?
When all objects are of the same type
What namespace is inherited by the following data structures?
Dictionary List Queue Stack SortedList
System.Collections.Generic