Which method is used to enforce garbage collection in .NET?

System.GC.Collect() method.

In .NET, you cannot explicitly force garbage collection. Garbage collection in .NET is managed by the Common Language Runtime (CLR), and it operates automatically based on various factors such as memory pressure, system resources, and generation thresholds.

However, if you absolutely need to suggest to the garbage collector that now might be a good time to perform a collection, you can use the GC.Collect() method. But it’s important to note that this method should generally be avoided in most scenarios, as it can interfere with the CLR’s optimized garbage collection algorithm and degrade performance.

So, the correct answer to the question “Which method is used to enforce garbage collection in .NET?” would be: GC.Collect(), but with a caution that it’s generally not recommended to use it except in very specific and rare scenarios where you have a deep understanding of the implications.