0
0
C Sharp (C#)programming~10 mins

Inspecting methods and properties in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the type of the object.

C Sharp (C#)
Type type = obj.[1]();
Drag options to blanks, or click blank then click option'
AEquals
BToString
CGetType
DGetHashCode
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToString() instead of GetType()
Trying to access a property instead of calling a method
2fill in blank
medium

Complete the code to get all public methods of a type.

C Sharp (C#)
MethodInfo[] methods = type.[1]();
Drag options to blanks, or click blank then click option'
AGetProperties
BGetConstructors
CGetFields
DGetMethods
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetProperties() instead of GetMethods()
Using GetFields() which returns fields, not methods
3fill in blank
hard

Fix the error in the code to get the name of the first property.

C Sharp (C#)
string propName = type.GetProperties()[[1]].Name;
Drag options to blanks, or click blank then click option'
A-1
B0
Cnull
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as index causing IndexOutOfRangeException
Using null which is invalid as an index
4fill in blank
hard

Fill both blanks to get all public properties and filter those with a specific type.

C Sharp (C#)
PropertyInfo[] props = type.[1]();
var stringProps = props.Where(p => p.PropertyType == typeof([2]));
Drag options to blanks, or click blank then click option'
AGetProperties
BGetMethods
Cstring
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetMethods() instead of GetProperties()
Using int instead of string for filtering
5fill in blank
hard

Fill all three blanks to get method names that have no parameters.

C Sharp (C#)
MethodInfo[] methods = type.[1]();
var noParamMethods = methods.Where(m => m.GetParameters().[2] == [3]);
Drag options to blanks, or click blank then click option'
AGetMethods
BLength
C0
DCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length on the parameters collection
Using 1 instead of 0 to check for no parameters