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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:56:13+00:00 2026-05-12T13:56:13+00:00

Currently I am trying to port some VB.NET code to C#. The struct looks

  • 0

Currently I am trying to port some VB.NET code to C#.

The struct looks like this in VB.NET:

Public Structure sPos
    Dim x, y, z As Single
    Function getSectorY() As Single
        Return Math.Floor(y / 192 + 92)
    End Function
    Function getSectorX() As Single
        Return Math.Floor(x / 192 + 135)
    End Function
    Function getSectorXOffset() As Int32
        Return ((x / 192) - getSectorX() + 135) * 192 * 10
    End Function
    Function getSectorYOffset() As Int32
        Return ((y / 192) - getSectorY() + 92) * 192 * 10
    End Function
End Structure

C# Version of the struct:

    public struct sPos
    {
        public float x;
        public float y;
        public float z;
        public float getSectorY()
        {
            return (float)Math.Floor(y / 192 + 92);
        }
        public float getSectorX()
        {
            return (float)Math.Floor(x / 192 + 135);
        }
        public Int32 getSectorXOffset()
        {
            return (int)((x / 192) - getSectorX() + 135) * 192 * 10;
        }
        public Int32 getSectorYOffset()
        {
            return (int)((y / 192) - getSectorY() + 92) * 192 * 10;
        }
    }

Why do I have to cast the return values to float & int ? In the vb version I don’t have to..

Thanks everyone.

  • 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-12T13:56:13+00:00Added an answer on May 12, 2026 at 1:56 pm

    Put a () after getXSectorOffset because it’s a function?

    example:

    nullPointX = pictureBox1.Width / 2 - sectorsize - centerPos.getSectorXOffset() / 10 * sectorsize / 192;
    

    Regarding the second question, you could avoid cast to float with this modification:

    public float getSectorY()
        {
            return (float)Math.Floor(y / 192f + 92f);
        }
    

    And sorry, you’ll have to cast to int still. Unless you cast the x and getXOffset() to int during the function:

    public Int32 getSectorXOffset()
        {
            return (((int)x / 192) - (int)getSectorX() + 135) * 192 * 10;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I am currently trying to port a .Net app to Objective C and Cocoa.
I am trying to port some C++ code from Windows to Solaris(Unix). There are
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console
I'm currently trying to read in an XML file, make some minor changes (alter
I'm currently trying out db4o (the java version) and I pretty much like what
My team is currently trying to automate the deployment of our .Net and PHP
I'm currently trying ElementTree and it looks fine, it escapes HTML entities and so
I’m working on trying to port an ASP.NET app from Server 2003 (and IIS6)
I'm trying to get some information from this tutorial: http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder basically I want to

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.