Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-24
3
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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