[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Array of Variables vs. Array of Object - VB.NET

1. Can you please explain the differences between the following array declarations and which is declaration correct?

    Private courseList As Course() = New Course(5) {}
    Private courseList(5) As Course()

2. I want i know is both declarations allow courseList to carry a reference to the actual object.

3. What about this one: Dim values() As Integer = {1, 2, 3}
Integer is a class, so what values will hold in here? Will it hold the actual number (1,2,3) or their references? If values hold the actual numbers 1,2,3 then Integer is not a class datatype, its a primitive because as i know array can hold actual values of primitive datatype values. Can you please clarify..

Thanks
0
F-J-K
Asked:
F-J-K
  • 5
  • 3
3 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
#1 - The second version should not have the () on the end so they would be:

    Private courseList As Course() = New Course(5) {}
    Private courseList(5) As Course

Other than that, there is no difference.  It's just two different ways of declaring the array.  The first version with the curly braces {} allows you to specify the initial contents but you're not actually putting anything in there so it's essentially equivalent to the second.

#2 - They both carry references because Course is a class.  In both versions, neither actually has any Course instances in it yet (despite having the "new" keyword as that is being used to declare a new array...not a new Course).

#3 - Integer is a value type (primitive) so it just holds the values.
0
 
F-J-KAuthor Commented:
"Integer is a value type (primitive) so it just holds the values."

What about String? There is String and string. Dim values As String = New String(3) {"xxx", "yyy", "zzz"}
Will these 3 values be stored as they are?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure I understand the question...

If you provide initial values in the brackets {} then you cannot also give it a size of 3.  You have to let it determine the size based on the values provided.

It would be written like this:

    Dim values() As String = {"xxx", "yyy", "zzz"}

Or this:

    Dim values As String() = {"xxx", "yyy", "zzz"}
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
F-J-KAuthor Commented:
Ok. Is String considered as a primitive datatype? What i know primitive datatype doesn't have attributes/behaviors. String variable can call various methods such as Substring, trim, etc, so to me
i see String as a class.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
String is considered a reference type:
http://msdn.microsoft.com/en-us/library/t63sy5hs(VS.80).aspx
0
 
F-J-KAuthor Commented:
Ok, what gets stored in values? (Dim values() As String = {"xxx", "yyy", "zzz"})
values(0) carries "xxx"? or carries a reference to "xxx"? I hope my question is clear
0
 
F-J-KAuthor Commented:
Discard my last question. Thanks
0
 
F-J-KAuthor Commented:
Thanks. Discard my last question
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now