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 8430095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:30:56+00:00 2026-06-10T05:30:56+00:00

With this sort of code: public void UpdateCellFont(int id, string colName, Font font) {

  • 0

With this sort of code:

    public void UpdateCellFont(int id, string colName, Font font)
    {
        CellLocation location = new CellLocation(id, colName);

        if (CellAppearances.ContainsKey(location))
        {
            CellAppearances[location].Font = font;
        }
        else
        {
            CellAppearance cell = new CellAppearance(font, _DefaultBackColor, _DefaultForeColor);
            CellAppearances.Add(location, cell);
        }
    }

    public void UpdateCellBackColor(int id, string colName, Color backColor)
    {
        CellLocation location = new CellLocation(id, colName);

        if (CellAppearances.ContainsKey(location))
        {
            CellAppearances[location].BackColor = backColor;
        }
        else
        {
            CellAppearance cell = new CellAppearance(_DefaultFont, backColor, _DefaultForeColor);
            CellAppearances.Add(location, cell);
        }
    }

    public void UpdateCellForeColor(int id, string colName, Color foreColor)
    {
        CellLocation location = new CellLocation(id, colName);

        if (CellAppearances.ContainsKey(location))
        {
            CellAppearances[location].ForeColor = foreColor;
        }
        else
        {
            CellAppearance cell = new CellAppearance(_DefaultFont, _DefaultBackColor, foreColor);
            CellAppearances.Add(location, cell);
        }
    }

The methods all do almost the same thing – each one updates Font, BackColor or ForeColor (or if there is no entry in the dictionary they create a new one.

How can I reduce the duplication here when they are acting on a strongly typed CellAppearance?

Thanks

  • 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-10T05:30:58+00:00Added an answer on June 10, 2026 at 5:30 am

    what about that straight-forward?

    public CellAppearance GetAppearance(int id, string colName){
        var location = new CellLocation(id, colName);
        if(!CellAppearances.ContainsKey(location))
           CellAppearances.Add(location, cell);
        return CellAppearances[location];
    }
    
    // usage:
    GetAppearance(1,"hello").Font = myFont;
    GetAppearance(2,"blubb").BackColor = myColor;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen this sort of code some places: public event SomeEventHandler SomeEvent = (s,
Can any one please describe this sort of code to understand Java closure. public
Here is my code: public class Main { public static void main(String[] args) {
This is my code...... public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView myLatitude =
I know this sort of code is not best practice, but nevertheless in certain
I have this code to sort an array of objects. The data in the
I got this code to sort an unordered list with regards to their title
I would like to sort this array but this code works if I do
This code is supposed to be able to sort the items in self.array based
hello I have this code that use to sort a datatable. Dim sortingIndex As

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.