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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:32:40+00:00 2026-05-11T18:32:40+00:00

i have several classes with members called ‘Id’. Originally i wanted to store these

  • 0

i have several classes with members called ‘Id’. Originally i wanted to store these as ints, but i would like some layer of protection, to make sure i don’t accidentally assign a room id to a person etc.

one solution would be typedef (using RoomId = System.Int32;) but then i need that line of code in all files using these. i would prefer e.g. a RoomId class derived from int32, but i can’t figure out how to set it up to allow explicit conversion (for initilisation)

or should i do this in some other way?

  • 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-05-11T18:32:40+00:00Added an answer on May 11, 2026 at 6:32 pm

    If I understand correctly, the only operation you really need is comparison for equality. You can create a RoomId class (or struct, whichever suits you)

    class RoomId
    {
        private int Value {get; set;}
    
        public RoomId(int value)
        {
            this.Value = value;
        }
    
        public bool Equals(RoomId other)
        {
            return this.Value == other.Value;
        }
    }
    
    RoomId room1 = new RoomId(1);
    RoomId room2 = new RoomId(2);
    
    // To compare for equality
    bool isItTheSameRoom = room1.Equals(room2);
    // Or if you have overloaded the equality operator (==)
    bool isItTheSameRoom = room1 == room2;
    

    You can implement IEquatable, overload the equality and inequality operators if you want. If you need persistence, you could implement the ISerializable interface to make sure that the integer value only “escapes” the class if it is really needed.

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

Sidebar

Related Questions

I have several classes such as Order, Customer, etc. These classes serve for holding
I have several classes, and want to work with their collections like with a
Sometimes we have several classes that have some methods with the same signature, but
I just realize some of my classes have no members. It has several public
I'm having some problems initializing static string members in c++. I have several classes
I have several classes like in the following example: abstract class AClass { boolean
I have several classes, that all derives from SuperClass. When the classes are created,
I have several classes each containing several methods annotated with @Test . The classes
If I have interface IFoo, and have several classes that implement it, what is
This is for a web project so i have several classes that inherit from

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.