?
Solved

C# Object Oriented Question

Posted on 2012-08-31
2
Medium Priority
?
870 Views
Last Modified: 2012-08-31
I was working with the System.ServiceModel.Syndication namespace and I was using an instance of the SyndicationItem class and I was trying to read a value from item.content property.  Item.content is of the type System.ServiceModel.Syndication.TextSyndicationContent and it has a property called text.  I was able to see this value in my  debugger and when I put a watch on it, it gave me this:
((System.ServiceModel.Syndication.TextSyndicationContent)(item.Content)).Text.  I have a good understanding of OOP, but I have never run into an instance where I needed to use this type of syntax.  I would like to someone to explain to me why I needed to read this value using this syntax.  Can someone explain to me why this works that way?  What does this statement: ((System.ServiceModel.Syndication.TextSyndicationContent)(item.Content)).Text mean?
0
Comment
Question by:guyriso
2 Comments
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 38354343
It just looks like a cast to me. Just like you can do (unsigned int)x in C to use x as an unsigned int.
The parentheses around item.Content are just because the system likes to add parentheses where it can to ensure nothing messes up if there is a more complicated expression used.

Then after the cast, the .Text property is accessed.

What I not positive on is why the system bothers casting if it already is that type. Perhaps it is just a safeguard like the extra parentheses or perhaps your variable is a derived type and it's casting back to the base type.
0
 

Author Comment

by:guyriso
ID: 38354473
I think I understand better now.  It I were to write item.content.text, I would say that text is a property of content.  Content does not have a property called text, the underlying datatype has the property of text therefore it had to be casted first to access that property.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question