Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8244661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:55:41+00:00 2026-06-07T21:55:41+00:00

My class has complicated property: private Image m_LogoImage=null; public Image LogoImage { get {

  • 0

My class has complicated property:

    private Image m_LogoImage=null;

    public Image LogoImage
    {
        get
        {
            if (m_LogoImage == null && File.Exists(Data.LogoFileUrl))
            {
                DrawingImage image = DrawingImage.FromFile(Data.LogoFileUrl);
                m_LogoImage = Image.GetInstance(image, new Color(1, 1, 1));
            }
            return m_LogoImage;
        }
    }

LogoImage.get is very slow and resource consuming action to the first time the client calls it, the property calculate the image and stored the result in private variable m_LogoImage.
This looks to me very basic. .NET support automatic properties (public string P {get;set;}). Does it support automatic storing of complicated properties?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:55:42+00:00Added an answer on June 7, 2026 at 9:55 pm

    There’re a number of state based concerns, so there’s no language level mechanics for lazy load.

    You can however use the Lazy<T> class to accomplish this functionality.

     private Lazy<Image> logo = new Lazy(() => LoadImage()); 
    
     public Image LogoImage
        {
            get
            {
                return logo.Value;
            }
        }
    

    You can also use the null coalescing operator (??) to do lazy load for nullable types.

    get 
    {
        return image ?? (image = LoadImage());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If a class has a private constructor then it can't be instantiated. So, if
I have a very complicated class(it has unordered_map and so on on inside it)
String class has a constructor: new String(byte[] bytes, Charset charset) and a method: byte[]
If a class has inheritance in a Java program, do I need to put
My base class has properties that are used by a subclass. where should Release
A TimeSheetActivity class has a collection of Allocations. An Allocation is a value object
The Object class has a number of methods such as equals, hashCode, notify, wait
A TreeNode class has Text Name Tag I need to assign more values to
why java Object class has two methods hashcode() and equals()? One of them looks
Although a static class has only one instance and can't be instantiated, a class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.