Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 10th, 2005, 11:06 AM
Registered User
 
Join Date: Oct 2004
Location: , , Indonesia.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Array to ref parameter

i want pass an array[] in ref parameter:

this is my code
//=========================

ArrayList[] myArrayList = new ArrayList[256];
byte T;
int j;

for( j = 0; j < myArrayList .length; j++)

{
    // i have method with parameter ref
    myMethod(ref myArrayList [j]);
    // i want the loop process in myMethod
}

//=========================

i have massage error" a property or indexer may not be passed to an out or ref paramenter"how can i do ..

regards,
dede
  #2 (permalink)  
Old February 11th, 2005, 02:54 AM
Registered User
 
Join Date: Feb 2005
Location: , , Singapore.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is it possible for you to pass the Array over and do the for loop in MyMethod ?

  #3 (permalink)  
Old February 11th, 2005, 04:08 AM
Registered User
 
Join Date: Oct 2004
Location: , , Indonesia.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

myMethod can't change cause i get it from DLL windows,,

regards,
ivan

  #4 (permalink)  
Old February 11th, 2005, 02:22 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

dedex,
you can't pass properteis or indexers to a ref parameter(however you can pass readonly properties),
Code:
void myMethod(ref myArrayList[j])
{
  ArrayList ar=new ArrayList();
  myArrayList[j]=ar;
}
if you set myArrayList[j] to a new object(ar) after you come out from the method,compiler can't assign new object(as type of Arraylist) to myArrayList[j] because its refrence is changed to a ArrayList Object,so C# compiler doesn't let this operation,
there is a solution for this explained here.

_____________
Mehdi.
software student.
  #5 (permalink)  
Old February 12th, 2005, 02:58 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

and its solution was,(in this way you can make sure the reference(on stack) to your indexer would not be erased)
Code:
for( j = 0; j < myArrayList.length; j++)
{
    ArrayList temp=myArrayList [j];
    myMethod(ref temp);
    myArrayList[j]=temp;
}
just out of my curiosity,can you tell which windows function you were calling?

_____________
Mehdi.
software student.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two Dimensional Array as parameter Manisha0605 .NET Framework 1.x 0 February 7th, 2007 04:15 PM
passing parameter array Maryann BOOK: Access 2003 VBA Programmer's Reference 0 December 4th, 2006 10:56 AM
convert from 'ref double[]' to 'ref object' wakeup C# 0 April 7th, 2006 05:14 AM
Pass an Array as a Parameter to a Stored Procedure booksnore2 Oracle 0 August 31st, 2004 09:20 AM
ActiveX + ASP -> array as parameter Berni016x Classic ASP Components 0 November 3rd, 2003 10:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.