
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Optional property in a C# class
A property is optional if it is possible and valid for it to have null. A property whose CLR type cannot have null cannot be configured optional.
An example optional attribute usage −
Example
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] internal sealed class OptionalAttribute : Attribute { } public class Employee { public string EmpName { get; set; } [Optional] public string AlternativeName { get; set; } }
- Related Articles
- Java 8 Optional Class
- How to get a stream from Optional class in Java 9?
- What are the new methods added to an Optional class in Java 9?
- Optional chaining operator in JavaScript.
- Optional Parameters in Dart Programming
- Handling optional/empty data in MongoDB?
- Explain Optional Catch Binding in JavaScript.
- How optional chaining works in TypeScript?
- Mandatory and optional Participation
- How to pass optional parameters to a function in Python?
- What are optional arguments in JavaScript Functions?
- What is an Optional parameter in C#?
- How to specify optional properties in TypeScript?
- Role of CSS :optional Selector
- How to make the argument optional in Python

Advertisements