Solved

How to pervent a VB function from modefying an array argument using it is interface?

Posted on 2007-11-24
3
165 Views
Last Modified: 2013-11-26
I got a VB.net function:
    Private Function Mean(ByVal A() As Double) As Double

I found that I can modify elements of A using the statement like
    A(3)=0
and I doesn't feel this is a good declaration of the function but couldn't find a better way.

How can I do it better?

Thank you!
0
Comment
Question by:huangs3
3 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20343492
You can't put anything in the declaration of the function that would prevent the access of the members of the array.

You can send something other than an array to the function, though. If the function only needs to loop throught the items, you could send the enumerator of the array instead:

Private Function Mean(A As Enumerator(Of Double)) As Double

Otherwise you could create a class that encapsulates the array, and only offers read access to it, and send an instance of that class to the function.
0
 

Author Comment

by:huangs3
ID: 20343498
I see, thank you GreenGhost
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20343501
not sure about what you are asking, you can initialize an array this way:

Dim arr As Double() = New Double() {0.2, 0.5, 0.87, 1.15, 3.14}
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error on Add method 1 50
Run time Error 4 47
Vb. Net application freezes 9 45
Why does my excel data start at B1 instead of A1. 9 80
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question