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

Built-in attributes (Obsolete, Serializable) in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the [Obsolete] attribute do in C#?
The [Obsolete] attribute marks a program element as outdated. When used, it warns developers that the element should not be used because it may be removed in the future.
Click to reveal answer
beginner
How do you make a class serializable in C#?
You add the <code>[Serializable]</code> attribute before the class definition. This tells the system that instances of the class can be converted into a format for storage or transfer.
Click to reveal answer
intermediate
What happens if you use [Obsolete] with a message?
You provide a custom message that appears as a warning when the obsolete element is used. This message can explain why it is obsolete or suggest an alternative.
Click to reveal answer
intermediate
Can the [Obsolete] attribute cause a compile error instead of a warning?
Yes. By setting the second parameter to true, like [Obsolete("message", true)], it causes a compile-time error instead of just a warning.
Click to reveal answer
beginner
Why is the [Serializable] attribute important?
It allows objects to be saved or sent over networks by converting them into a format that can be stored or transferred, then reconstructed later.
Click to reveal answer
What does the [Obsolete] attribute do?
AImproves performance
BMakes a class serializable
CEncrypts the class data
DMarks code as outdated and shows a warning
How do you mark a class as serializable?
AAdd <code>[Serializable]</code> before the class
BAdd <code>[Obsolete]</code> before the class
CUse <code>static</code> keyword
DUse <code>sealed</code> keyword
What happens if you use [Obsolete("Use NewMethod", true)]?
AIt serializes the method
BIt causes a compile error if used
CIt makes the method faster
DIt shows a warning only
Which attribute is used to allow an object to be saved or sent over a network?
A[NonSerialized]
B[Obsolete]
C[Serializable]
D[ThreadStatic]
Can [Obsolete] attribute be used without any parameters?
AYes, it shows a default warning
BNo, parameters are required
CYes, but it causes an error
DNo, it disables the method
Explain how the [Obsolete] attribute works and how you can customize its behavior.
Think about how you warn others not to use old code.
You got /4 concepts.
    Describe the purpose of the [Serializable] attribute and when you would use it.
    Consider when you want to save or send an object.
    You got /3 concepts.