C# - GC.MaxGeneration Property with Example

In this tutorial, we will learn about the GC.MaxGeneration property with its definition, usage, syntax, and example. By Nidhi Last updated : April 03, 2023

GC.MaxGeneration Property

The GC.MaxGeneration property is used to get the maximum number of generations that the system currently supports.

Syntax

public static int MaxGeneration { get; }

Parameter(s)

  • None

Return Value

It returns the maximum number of supported generations.

Example: C# program to get the maximum number of generations that the system currently supports

The source code to get the maximum number of generations that the system currently supports is given below. The given program is compiled and executed successfully.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
  class Program {
    static void Main(string[] args) {
      Console.WriteLine("Total number of HEAP generations are: " + GC.MaxGeneration);
      Console.WriteLine();
    }
  }
}

Output

Total number of HEAP generations are: 2

Press any key to continue . . .

C# Garbage Collection Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.