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

Why can't a Dictionary be safe_cast to an Object

Why can't I safe_cast a Dictionary to an Object?

Generic::Dictionary<String^, String^Dict = gcnew
Generic::Dictionary<String^, String^>();
Object^ DictObject = safe_cast<Object ^>(Dict);

Anyone know why the compiler won't handle this syntax?

Dave

Oct 16 '07 #1
3 1308
Why can't I safe_cast a Dictionary to an Object?
>
Generic::Dictionary<String^, String^Dict = gcnew
Generic::Dictionary<String^, String^>();
Object^ DictObject = safe_cast<Object ^>(Dict);

Anyone know why the compiler won't handle this syntax?

Dave
You have a mistake in your 'Dict' declaration. You have to declare it like a
managed reference:

Generic::Dictionary<String^, String^>^ Dict = gcnew Generic::Dictionary<String^,
String^>();

Regards
--
Cholo Lennon
Bs.As.
ARG
Oct 16 '07 #2
Thanks, that fixed it

"Cholo Lennon" <ch*********@hotmail.comwrote in message
news:O2**************@TK2MSFTNGP05.phx.gbl...
>Why can't I safe_cast a Dictionary to an Object?

Generic::Dictionary<String^, String^Dict = gcnew
Generic::Dictionary<String^, String^>();
Object^ DictObject = safe_cast<Object ^>(Dict);

Anyone know why the compiler won't handle this syntax?

Dave

You have a mistake in your 'Dict' declaration. You have to declare it like
a
managed reference:

Generic::Dictionary<String^, String^>^ Dict = gcnew
Generic::Dictionary<String^,
String^>();

Regards
--
Cholo Lennon
Bs.As.
ARG

Oct 16 '07 #3

"Cholo Lennon" <ch*********@hotmail.comwrote in message
news:O2**************@TK2MSFTNGP05.phx.gbl...
>Why can't I safe_cast a Dictionary to an Object?

Generic::Dictionary<String^, String^Dict = gcnew
Generic::Dictionary<String^, String^>();
Object^ DictObject = safe_cast<Object ^>(Dict);

Anyone know why the compiler won't handle this syntax?

Dave

You have a mistake in your 'Dict' declaration. You have to declare it like
a
managed reference:

Generic::Dictionary<String^, String^>^ Dict = gcnew
Generic::Dictionary<String^,
String^>();
This should also work:

Generic::Dictionary<String^, String^Dict;
Object^ DictObject = %Dict; // managed address-of -- but managed
deference is still *, not ^ if I remember right
>
Regards
--
Cholo Lennon
Bs.As.
ARG


Oct 16 '07 #4

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

Similar topics

1
by: none | last post by:
or is it just me? I am having a problem with using a dictionary as an attribute of a class. This happens in python 1.5.2 and 2.2.2 which I am accessing through pythonwin builds 150 and 148...
0
by: Feghhi, Jalil | last post by:
I get an error storing an object in a dictionary. The dictionary and the object are both provided by mod_python. One is the session object (which is just a dictionary) and one is a FieldStorage...
4
by: Bill Woodruff | last post by:
< note : this message was sparked in part by comments by David Browne on a previous thread : "inserting an anonymous method as a value in a generic dictionary ?" : David had shown the use of...
3
by: kim.nolsoee | last post by:
Hi I want to use the Dictionary Classs that will load my own class called KeyClass used as TKey. Here is the code: public class Dictionary { public static void Main()
15
by: Dave Young | last post by:
I'm trying to replicate the behaviour of the Commerce.Dictionary object that was found in Commerce Server 3.0 By using a hashtable or creating a custom class that implements IDictionary, you...
3
by: Al Meadows | last post by:
I'm using a generic Dictionary object where it is described as: Dictionary<this, thatstuff = new Dictonary<this, that>() Where THIS is a class with several property values. This works fine...
2
by: =?Utf-8?B?U2hhd24=?= | last post by:
Hi; I would like to be able to use the XMLSerializer to serialize and deserialize a dictionary. is that possible? i know that you can serialize an object that implements the ICollection interface....
1
by: GVDC | last post by:
Example server-side JavaScript Web script, Dictionary class //Dictionary class, hash array unlimited length configurable speed/efficiency // printf("<html><body>"); printf("<b>Creating...
1
by: sachin2 | last post by:
I am using 3 types of dictionaries. 1) Dictionary<string, string > d = new Dictionary<string, string>(); 2) Dictionary<string, List<string>> d = new Dictionary<string, List<string>>(); 3)...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.