I currently have an inner class. Is it possible to convert it to a method?

public class AreaExceptions : List<Rect> { public bool Contains(Vector3 point) { foreach(var item in this) { if (item.Contains(point) return true; } return false; } } 

Even reformulate the question. Here is the code

 List<Rect> Rects; public bool Contains(Vector3 point) { foreach(var item in Rects) { if (item.Contains(point) return true; } return false; } 

Will he perform the same function?

    1 answer 1

    In the Clamp reply, I wrote about extension methods. Also here in the comments mentioned that you can extend the List. As I recall, you already have one class that contains the extension. You can add a new method there.

     public bool Contains(this List<Rect> source, Vector3 point) { foreach(var item in source) { if (item.Contains(point) return true; } return false; } 

    After that, any instance of List (Rect) will have a method Contains, if it will see a class with the extension