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

  • Home
  • SEARCH
  • 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 8582345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:16:10+00:00 2026-06-11T21:16:10+00:00

I’ve been tasked with converting some legacy code to a new system and we’ve

  • 0

I’ve been tasked with converting some legacy code to a new system and we’ve got some VB6 structures that are here. Is there a way to convert them into a C# structure easily?

I could redefine the structure in C# but there’s no fixed strings in C#. (Or maybe I misunderstand)

Any prods in the right direction?

Private Type MapRec
    Name As String * NAME_LENGTH
    Revision As Long
    Moral As Byte
    Up As Integer
    Down As Integer
    Left As Integer
    Right As Integer
    Music As String
    BootMap As Integer
    BootX As Byte
    BootY As Byte
    Tile() As TileRec
    Npc(1 To MAX_MAP_NPCS) As Integer
    NpcSpawn(1 To MAX_MAP_NPCS) As SpawnRec
    TileSet As Integer
    Region As Byte
End Type
  • 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-11T21:16:11+00:00Added an answer on June 11, 2026 at 9:16 pm

    With respect to fixed-length strings, yikes. It ain’t gonna happen because there is no equivalent construct. Unless Jon Skeet or Anders Hejlsberg know differently and can be invoked to weigh in — I don’t think even they know a way, cuz there ain’t one, I am pretty certain.

    On the other hand, fixed-length strings are absolutely Satanic. Which is why they didn’t include them in .NET. 🙂

    If you were to ask me how I would convert the above MapRec object to something usable in C#, well you kind of have your choice between a struct and a class. Personally, I dislike structs. If you used a class, then you could implement a kind of bastardized fixed-string by way of your setters and getters. As seen in this example, which is how I would implement your Type MapRec:

    public class MapRec
    {
        private const int MAX_MAP_NPCS = 25;
        private int fixedLength1 = 10;
        private string _name;
    
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                if (value.Length != fixedLength1)
                {
                    if (value.Length < fixedLength1)
                    {
                        _name = value.PadRight(fixedLength1);
                    }
                    else
                    {
                        _name = value.Substring(0,fixedLength1);
                        // or alternatively throw an exception if 
                        // a 11+ length string comes in
                    }
                }
                else
                {
                    _name = value;
                }
            }
        }
    
        // Constructor
        public MapRec()
        {
            Npc = new int[MAX_MAP_NPCS];
            NpcSpawn = new SpawnRec[MAX_MAP_NPCS];
        }
    
        public long Revision { get; set; }
        public byte Moral { get; set; }
        public int Up { get; set; }
        public int Down { get; set; }
        public int Left { get; set; }
        public int Right { get; set; }
        public string Music { get; set; }
        public int BootMap { get; set; }
        public byte BootX { get; set; }
        public byte BootY { get; set; }
        public TileRec[] Tile { get; set; }
        public int[] Npc { get; set; }
        public SpawnRec[] NpcSpawn { get; set; }
        public int TileSet { get; set; }
        public byte Region { get; set; }
    }
    

    In the end, unless one actually needs a fixed-length string (and perhaps Microsoft.VisualBasic.VBFixedStringAttribute could do the job), I would suggest staying the heck away from them.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.