Lazy Loading Objects in C-Sharp [Speed Complexity]

Dot Net Lazy Loading Class

When developing a Software or any other application, keep in mind how the data is being loaded. Bad practice is calling a function in the constructor, this is bad because data might end uploaded without need. The solution to this is creating properties in the class e.g. public void getObject(){thy shall return something;} this way, you only load object when in need. If the Get-Function returns a list of Objects, you can even do this: foreach(var o in Instance.getObject()){//do something here}, remember if you want to just load the object from the List or Dictionary use "foreach" instead of "for" Loop.

The idea here is to only load objects that you need, instead of overloading the system with a bunch of data that is not needed at that time. However, Dot-Net has included an inbuilt class called "Lazy" in order to implement this class just wrap your function; public void List


© 2024 - ErnesTech - Privacy
E-Commerce Return Policy