Use lambda as member method - CSharp Custom Type

CSharp examples for Custom Type:Lambda

Description

Use lambda as member method

Demo Code

using System;/*from  w w  w . j a va 2 s.c om*/
using System.Collections.Generic;
using System.Text;
public class Person
{
   public string FirstName { get; private set; }
   public string LastName { get; private set; }
   public string FullName => $"{FirstName} {LastName}";
   private int _age;
   public int Age
   {
      get => _age;
      set => _age = value;
   }
   public Person(string firstName, string lastName, int age) => init(firstName, lastName, age);
   private void init(string firstName, string lastName, int age)
   {
      FirstName = firstName;
      LastName = lastName;
      Age = age;
   }
   ~Person() => Console.WriteLine("Finalizing Person object");
   public override string ToString() => FullName;
}
class Program
{
   static void Main(string[] args)
   {
      Console.ReadKey();
   }
}

Related Tutorials