Solved

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

Posted on 2007-11-24
3
157 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now