473,386 Members | 1,827 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,386 software developers and data experts.

C# pointers??

Hi All,

I am creating a C# Windows Forms application,
here is my problem :

in my main form, I have this variable : List<List<cBar>bars;

I will save you the initialization and loading phases of this, but at
the end, this variable contains well, a list of list of bars. For the
sake of the example, let's say a bar is simply an int, so that
variable would roughly be equivalent to a jagged 2-d array of
integers.

bars[0] = { 1, 4, 7, 8, 9 }
bars[1] = {6, 3, 5 }
bars[2] = { 2, 6, 8, 9, 8, 7}
....

I also have a usercontroler on the form. Again for simplicity's sake,
let's say it simply prints all the bars (ints)
For now, as I am still testing, I hardcoded one such list of bars in
the user control and it works great.

So the next step is to integrate the user control in the form so that
when I select a List of bars from the main form ( let's say bars[0] ),
the user control uses it and prints it.

My main concern now : I do not want to pass a List<cBarby value
parameter to the user control. I want of course to pass a reference of
the list instead, to avoid the tedious process of copying all the data
in the list.

So, for now, when I select a list, I use the following :

userControl.LoadData( bars[selectedList] );

I need to pass a reference to the user control instead of copying the
whole list, how do I do?

Hope this is clear enough,
thanks to all who help!
Nov 5 '08 #1
5 1704
On Nov 5, 4:07*pm, ibiza <lambe...@gmail.comwrote:
Hi All,

I am creating a C# Windows Forms application,
here is my problem :

in my main form, I have this variable : List<List<cBar>bars;

I will save you the initialization and loading phases of this, but at
the end, this variable contains well, a list of list of bars. For the
sake of the example, let's say a bar is simply an int, so that
variable would roughly be equivalent to a jagged 2-d array of
integers.

bars[0] = { 1, 4, 7, 8, 9 }
bars[1] = {6, 3, 5 }
bars[2] = { 2, 6, 8, 9, 8, 7}
...

I also have a usercontroler on the form. Again for simplicity's sake,
let's say it simply prints all the bars (ints)
For now, as I am still testing, I hardcoded one such list of bars in
the user control and it works great.

So the next step is to integrate the user control in the form so that
when I select a List of bars from the main form ( let's say bars[0] ),
the user control uses it and prints it.

My main concern now : I do not want to pass a List<cBarby value
parameter to the user control. I want of course to pass a reference of
the list instead, to avoid the tedious process of copying all the data
in the list.

So, for now, when I select a list, I use the following :

userControl.LoadData( bars[selectedList] );

I need to pass a reference to the user control instead of copying the
whole list, how do I do?

Hope this is clear enough,
thanks to all who help!
You do pass it by reference. as List<is a reference type.
Nov 5 '08 #2
lists are reference-types; that means that you *are* passing just a
reference (comparable to a pointer), and the data is never copied.

Are you having an issue in this area? If so, could you describe the
symptom and/or provide any error messages you are seeing?

Marc
http://marcgravell.blogspot.com/
Nov 5 '08 #3
ok great :)

I do not have an issue beside that I assumed that was passed by
value...

thanks!
Nov 5 '08 #4
ibiza wrote:
ok great :)

I do not have an issue beside that I assumed that was passed by
value...
Well it is passed by value - you're passing the reference by value.

See http://msdn.microsoft.com/en-us/libr...0z(VS.71).aspx or
ECMA-334 for more details.

Alun Harford
Nov 6 '08 #5
On Wed, 05 Nov 2008 13:13:10 -0800, Ignacio Machin ( .NET/ C# MVP )
<ig************@gmail.comwrote:
[...]
>I need to pass a reference to the user control instead of copying the
whole list, how do I do?

You do pass it by reference. as List<is a reference type.
Careful though: you're right that a reference is passed and that addresses
the specific concern of the OP. But the reference is not passed "by
reference". It's passed "by value".
Nov 6 '08 #6

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

Similar topics

27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
3
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL,...
9
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar...
12
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
4
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token...
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.