473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

pass system.array by ref?

first off, I am an IT pro trying to dust off the cobwebs of programming in a
Master degree program so please be nice:)

I am trying to pass a system.array object by reference to a procedure (or
class) and keep getting the compile error "an object reference is required
for the nonstatic field, method, or property... (you know the rest) .. please
look at my code and tell me why my pass by reference is not working

static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
try
{
Array arrayHeap = Array.CreateInstance(typeof(int),0);

// THIS SYSTEM.ARRAY WILL RESIZE and HAVE Array.Length > 1
arrayHeap = Class1.Collect_InputFiles(sInputFile1, sInputFile2, arrayHeap);

//****THIS IS MY PROBLEM STATEMENT
Heapify(ref arrayHeap,arrayHeap.Length);

}
catch(Exception e)
{
Console.WriteLine("exception " + e.ToString());
}
}

public void Heapify(ref System.Array tempHeap, int n)
{
Console.WriteLine("Begin Heapify");
try
{
Console.WriteLine("i/2 will be =" + n/2);

for (int i = n/2; i >= 1; i--)
{
Console.WriteLine("Heapify : Loop #" + i.ToString());

//****I WANT TO STILL REFERENCE THE SAME ARRAY HERE

SiftDown(ref tempHeap,i,n);

}
}
catch (Exception e)
{
Console.WriteLine("exception " + e.ToString());
}
}

public void SiftDown(Array arrayHeap, int i , int n)
{

try
{
int temp = Convert.ToInt32(arrayHeap.GetValue(i-1));

while (2*i <= n)
{
int child = 2 * i;

if ((child < n)
&& (Convert.ToInt32(arrayHeap.GetValue(child)) >
Convert.ToInt32(arrayHeap.GetValue(child-1))))
{
child = child + 1;

}

if (Convert.ToInt32(arrayHeap.GetValue(child-1)) > temp)
{
arrayHeap.SetValue(Convert.ToInt32
arrayHeap.GetValue (child-1)),i-1);
}
else
{
break;
}

i = child;
}

arrayHeap.SetValue(temp, i-1);
}
catch(Exception e)
{
Console.WriteLine("exception " + e.ToString());
}

}

Nov 16 '05 #1
0 1586

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Morgan | last post by:
I have read much posts on the argument but no one clearly says if this operation is possible or not. Simply I have a routine which reads from a text file some integer arrays (1 or 2D). The...
5
by: wilson | last post by:
Dear all, In this time, I want to pass array to function. What should I declare the parameter in the function?i int array or int array? Which one is correct? ...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
2
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
1
by: Anaro | last post by:
Greetings This is all in VB.net 2005 I am trying to make a programme that will take in a completed survey and then store that survery object within an array. Currently i know my Surveyclass...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
1
by: vipinsoni | last post by:
Hi all, I am stucked with a problem. I have to paas a System.Array of object to my unmanaged C code as a void* I have a class of 'PointZ' which stores x, y,z coordinate and have some methods.I...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.