C#
using System;
namespace ConsoleApplication1
{
class Book
{
public void ShowBook(int price)
{
Console.WriteLine("Hello!");
}
}
class Program
{
static void Main(string[] args)
{
// имя класса
string str1 = nameof(Book);
// str1 = "Book"
Console.WriteLine(str1);
// имя метода
string str2 = nameof(Book.ShowBook);
// str2 = "ShowBook"
Console.WriteLine(str2);
// имя переменной
int myYear;
string str3 = nameof(myYear);
// str3 = "myYear"
Console.WriteLine(str3);
}
}
}
C#
public void ShowReport(MyReportType myReportType, long key)
{
if (myReportType == MyReportType.Film)
{
ShowFilmReport(key);
}
else if (myReportType == MyReportType.Book)
{
ShowCarReport(key);
}
else
{
throw new InvalidOperationException(nameof(myReportType) + " is undefined"));
}
}
C#
[HttpPost]
[ActionName(nameof(Add))]
public virtual async Task<IActionResult> AddBook(BookViewModel viewModel)
{
...
}