473,399 Members | 3,038 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.

casting issue

I am kind of new to c# language and looking for assistance on how the
following piece of code works.

objectDefinitions.Add((ObjectDefinition)((ArrayLis t)myGenericAnalysisWindow.comboBox2.Tag)[myGenericAnalysisWindow.comboBox2.SelectedIndex]);

- ObjectDefinition: is a self defined class
- objectDefinitions: is an instance of the ArrayList class
- myGenericAnalysisWindow is some window with a combobox
I do not understand how the casting works here and in what way squared
brackets are used.

Help is very much appreciated. Thanx.
May 3 '06 #1
2 1090
> I am kind of new to c# language and looking for assistance on how the
following piece of code works.

objectDefinitions.Add((ObjectDefinition)((ArrayLis t)myGenericAnalysisWindow.comboBox2.Tag)[myGenericAnalysisWindow.comboBox2.SelectedIndex]);

- ObjectDefinition: is a self defined class
- objectDefinitions: is an instance of the ArrayList class
- myGenericAnalysisWindow is some window with a combobox
I do not understand how the casting works here and in what way squared
brackets are used.

Help is very much appreciated. Thanx.


1) you take myGenericAnalysisWindow.comboBox2.Tag
2) this you cast to ArrayList
3) with the [] you get one item from this list: index is
myGenericAnalysisWindow.comboBox2.SelectedIndex
4) this item you cast to ObjectDefinition
5) you add that to your objectDefinitions list.
Hans Kesting
May 3 '06 #2
the Tag in the combobox is cast to an arraylist from which the item at the
selectedindex of the combo is chosen. the result is cast to ObjectDefinition
and then added to the objectDefinitions list.

--
"Glenn" <gl****@web.de> schrieb im Newsbeitrag
news:e3**********@sagnix.uni-muenster.de...
I am kind of new to c# language and looking for assistance on how the
following piece of code works.

objectDefinitions.Add((ObjectDefinition)((ArrayLis t)myGenericAnalysisWindow.comboBox2.Tag)[myGenericAnalysisWindow.comboBox2.SelectedIndex]);

- ObjectDefinition: is a self defined class
- objectDefinitions: is an instance of the ArrayList class
- myGenericAnalysisWindow is some window with a combobox
I do not understand how the casting works here and in what way squared
brackets are used.

Help is very much appreciated. Thanx.

May 3 '06 #3

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

Similar topics

5
by: dis | last post by:
I've been going through my code and clearing away some of the compiler warnings that i'm generating and i've come across areas where i cast pointers to integer values. The Visual Studio compiler...
4
by: David Rager | last post by:
Howdy, Put briefly, I have an array of chars, which I would like to access in pairs of bytes via casting the array to an array of shorts. I'm trying to be as elegant as possible. Below is a...
231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
35
by: ytrama | last post by:
Hi, I have read in one of old posting that don't cast of pointer which is returned by the malloc. I would like to know the reason. Thanks in advance, YTR
7
by: yufufi | last post by:
lets say we have a 'shape' class which doesn't implement IComparable interface.. compiler doesn't give you error for the lines below.. shape b= new shape(); IComparable h; h=(IComparable)b;...
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
1
by: Jay Hamilton | last post by:
Hello, I am running into an invalid address alignment error on an HPUX box when I attempt to lookup a value in a STL map. The argument being passed in is a double, which is accessed from a...
19
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting more often than creating an instance of objects. like : protected void gvOrderDetailsRowDataBound(object sender,...
8
by: Bob Hoeppner | last post by:
In the following code //add to bool or double Dictionary this.m_unit.Add((unittype == "b")? unitnum:(double)unitnum); The bool dictionary uses an integer index, the double uses a double...
4
by: AndreH | last post by:
Good day, I have the a bit of an issue with retrieving an object from php's session. I set a session variable "user" from the class User as follows: $user = new User(); // ... do some stuff...
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: 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...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.