- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The nameof keyword in C#
The nameof operator returns a string literal of an element that can be a variable, type or member.
For example, the following is our variable −
var vehicle = "motorbike";
To get the string literal, use nameof −
nameof(vehicle);
The following is the code to implement nameof keyword −
Example
using System; public class Program { static void Main() { var vehicle = "motorbike"; Console.WriteLine(nameof(vehicle)); var time = DateTime.Now.ToLocalTime(); Console.WriteLine(nameof(time)); var a = false; Console.WriteLine(nameof(a)); } }
Output
vehicle time a
Advertisements
To Continue Learning Please Login
Login with Google