|
-
August 7th, 2012, 09:54 PM
#2
Re: Problem related to the use reference
You don't need to use the ref keyword, since arrays are reference types, which means they are passed by reference anyway - so the parameter will point to the same list. That's the reason why your o1 object ends up empty - it's the same list. Now, your else branch will only be true for numbers1[i] == 9, when, I suppose, you are trying to add a list of numbers 1-8? You can go two ways with this: either create an empty list in the constructor of object1, provide a way to get the list (e.g. via a property), and then call Add() on it for each number in listMain, or make a copy of listMain, and pass that. You'll have to provide a way to retrieve the data in mChiffres anyway, unless you just wanna use it internally in the object1 class.
A tip: instead of ArrayList, better use the generic List<T>, where T is a type parameter (List<int> for ints, List<object1> for instances of object1), so that the data doesn't have to be stored as object type. BTW, "object1" is not exactly the best name for a class... Especially because "objects" usually designate instances of a class. Try finding something more descriptive.
Also, in C#, most people follow this naming convention: camelCase for private member variables and function parameters, PascalCase for public class, method and property names. Makes it easier for others to read and understand your code.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|