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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:36:13+00:00 2026-06-13T13:36:13+00:00

I am trying to create a data structure CityPosition , in which to have

  • 0

I am trying to create a data structure CityPosition, in which to have 3 variables: CityName, PositionX, PositionY.

I tried creating a class:

Public Class CityPosition
   Public Shared CityName As String
   Public Shared LocX As Double
   Public Shared LocY As Double

   Public Sub New(ByVal name, ByVal x, ByVal y)
       CityName = name
       LocX = x
       LocY = y
   End Sub
End Class

As I have to collect lots (unknown number) of instances of that class, I created an ArrayList element:

Dim CityPositions As New ArrayList

Finally, I am trying to add an instance of the class to the ArrayList by this:

CityPositions.Add(New CityPosition(Positions(0), LocX, LocY))
  1. Please let me know if I am doing it right, because I am a VB.NET newbie.
  2. How to access the instance properties? I tried CityPositions(0).CityName but it seems not to work
  • 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-13T13:36:14+00:00Added an answer on June 13, 2026 at 1:36 pm

    Remove “Shared” from your public fields as shown below.

    Public Class CityPosition
       Public CityName As String
       Public LocX As Double
       Public LocY As Double
    
       Public Sub New(ByVal name As String, ByVal x As Double, ByVal y As Double)
           CityName = name
           LocX = x
           LocY = y
       End Sub
    End Class
    

    Also, it is preferable to use Properties instead of Public fields within a class.

    http://msdn.microsoft.com/en-us/library/dd293589.aspx

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

Sidebar

Related Questions

I'm trying to create a matrix data structure in C. I have a struct
Today i was told to create tree data structure with the below class, public
I'm trying to create my first data mart. I am creating my dimension table
The task: I am trying to create a custom data type and have it
I am trying to create a data structure to hold polynomials. So far i
I am trying to create a CvMat data structure using cvMat() in OpenCV. The
I am trying to have a data structure with multiple string keys. To do
I am trying to create a deep copy of my binary tree data structure
I am trying to create a data structure called Disjoint Set. Looking at theory
I am trying to create a subclass of a Pandas data structure to substitute,

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.