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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:00:02+00:00 2026-06-12T06:00:02+00:00

I have a class with static properties. I want this class to have a

  • 0

I have a class with static properties. I want this class to have a static, read only dictionary – and I want to initialize it anonymously. I’ve tried the following but it doesn’t work:

    public static readonly Guid ID1 = new Guid("53ba029b-0850-4f51-a358-648411e30972");
    public static readonly Guid ID2 = new Guid("400a9861-21c3-45fd-bf75-95be8f535c58");

public static readonly Dictionary<Guid, String> IdsAndStrings = new Dictionary<Guid, string>(){
    {ID1, "string"},
    {ID2, "string 2"}
};

I’m getting an exception when trying to initialize this. The inner exception even mentions incorrect conversion to datetime!? Not sure what’s going on there. Is it impossible to instance a new Dictionary<> like this? Should I be using Get Set instead?

EDIT: Please assume all guids and strings are valid.

  • 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-12T06:00:04+00:00Added an answer on June 12, 2026 at 6:00 am

    No, it is not impossible. Using collection initializers, it would look like this:

    Dictionary<Guid, string> idsAndStrings = new Dictionary<Guid, string>
    {
        { Guid.NewGuid(), "" },
        { Guid.NewGuid(), "" },
    };
    

    Get/set would expose the item as a writable property, which is semantically different to a readonly field – it will offer different behaviour in some cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I have is a class with static properties that I want to use
I have a class with static members. I want to get a list of
I have this class: public static class CsvWriter { private static StreamWriter _writer =
say I have: class Test { public static int Hello = 5; } This
I have a static class in a shared project, which I want to extend
I have a class called EditMapUtilities. Here are some class properties that I want
I have a Car class with various properties. I have a static Cars collection
In Winform application I have a class with 2 properties and I want the
I want to have compact class based python DSLs in the following form: class
I have a static class Foo (this isn't a real class, so static fields

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.