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

Difference between casting by as and normal cast

I wondering what is the difference between the following two casts

DictionaryEntry entry = obj as DictionaryEntry;
AND

DictionaryEntry entry = (DictionaryEntry)obj;
Nov 19 '05 #1
2 962
Hello !

The first one will return null if the types are not compatible instead of raising an exception for the second case.

Best Regards

Yves Peneveyre

Raed Sawalha<Ra*********@discussions.microsoft.com> 15.08.2005 14:49:03 >>>

I wondering what is the difference between the following two casts

DictionaryEntry entry = obj as DictionaryEntry;
AND

DictionaryEntry entry = (DictionaryEntry)obj;
Nov 19 '05 #2
> DictionaryEntry entry = obj as DictionaryEntry;

returns null if cast fails
DictionaryEntry entry = (DictionaryEntry)obj;


throws invalidcastexception when cast fails

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #3

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

Similar topics

4
by: destroyedlolo | last post by:
Hi all, I just upgrade my workstation to Gcc 3.3, and I got a very strange probleme with casting : I got an error if I try to get the adress of a "casted" pointer. ---- dumy example source...
9
by: Simon | last post by:
Hi All, Is it possible to disallow implicit casting for an operand of a function written in C? i.e. void foo(int a) {..} short b; foo(b) // error without explicit cast
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...
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;...
1
by: Remco | last post by:
Hi, Let me try to simply explain my questions. I've created a portal site with different types of users, e.g. Portal Administrators and Normal Users. One base class SessionUser (has a enum...
14
by: Vols | last post by:
If the people ask what is the different between pointer and reference, what is the brief and good answer? I say " pointer could point to NULL, but there is no null reference", What is your...
13
by: In a little while | last post by:
thanks
6
by: Nishu | last post by:
Hi all, What is difference between typecasting and casting? I used to think that both are same; but few days back someone pointed out here that these are different. Vague guess, Is it that...
0
by: Michael Rudolph | last post by:
Hi DB2 newsgroup, I have encountered a difference between our development DB2 on Windows and the test environment on AIX. If using the LOCATE scalar function with a SMALLINT as LENGTH parameter...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...

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.