The Artima Developer Community
Sponsored Link

.NET Buzz Forum
C# Casting Quiz

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
John Papa

Posts: 66
Nickname: papajohn
Registered: Apr, 2005

John Papa is .NET lead developer/architect/author
C# Casting Quiz Posted: May 12, 2005 6:22 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by John Papa.
Original Post: C# Casting Quiz
Feed Title: John Papa
Feed URL: /error.htm?aspxerrorpath=/blogs/john.papa/rss.aspx
Feed Description: .NET Code Samples, Data Access, Patterns and Other Musings
Latest .NET Buzz Posts
Latest .NET Buzz Posts by John Papa
Latest Posts From John Papa

Advertisement

There are several ways to convert and cast values in .NET. For example, DirectCast versus System.Convert and if you are a VB.NET'er, you have the CInt, CBool, Cxxx functions. It is along these lines that I offer this quiz: What are the differences between the following ways to cast an object?

 

Casting quiz
/// Technique #1
object item = GetIt();
Dog dog = (Dog)item;

/// Technique #2
object item = GetIt();
Dog dog = item as Dog;


public object GetIt()
{
    object x = null;
    /// Does something that tries to get an instance of an object
    ...
    ...
    ...
    return x;
}

What is the difference between these 2 techniques of casting and when would you want to use one over the other?

Read: C# Casting Quiz

Topic: Folien und Demos zum MSDN TechTalk "Web Services, sechs Jahre später: Missverständnis oder... Previous Topic   Next Topic Topic: Managed Code Game Development & Coding4Fun Articles

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use