473,581 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# equivalent to TryCast

Will somebody convert this for me...

System.Web.UI.H tmlControls.Htm lHead header;
header = TryCast(this.Pa ge.Header, System.Web.UI.H tmlControls.Htm lHead);

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-...8&z=17&l=0&m=h
Nov 27 '06 #1
21 48940
System.Web.UI.H tmlControls.Htm lHead header;
header = this.Page.Heade r as System.Web.UI.H tmlControls.Htm lHead;
if (header == null)
// cast failed...
else
// cast succeeded...

Best Regards,
Dustin Campbell
Developer Express Inc.
Nov 27 '06 #2
Thanks...

<%= Clinton

"Dustin Campbell" <du*****@no-spam-pleasedevexpres s.comwrote in message
news:c1******** *************** ***@news.micros oft.com...
System.Web.UI.H tmlControls.Htm lHead header;
header = this.Page.Heade r as System.Web.UI.H tmlControls.Htm lHead;
if (header == null)
// cast failed...
else
// cast succeeded...

Best Regards,
Dustin Campbell
Developer Express Inc.


Nov 27 '06 #3
You can also use the "is" keyword

System.Web.UI.H tmlControls.Htm lHead header;

if (this.PageHeade r is System.Web.UI.H tmlControls.Htm lHead)
{
header = (this.PageHeade r as
System.Web.UI.H tmlControls.Htm lHead);
}

On Nov 28, 7:58 am, "clintonG"
<csgallag...@RE MOVETHISTEXTmet romilwaukee.com wrote:
Thanks...

<%= Clinton

"Dustin Campbell" <dust...@no-spam-pleasedevexpres s.comwrote in messagenews:c1* *************** **********@news .microsoft.com. ..
System.Web.UI.H tmlControls.Htm lHead header;
header = this.Page.Heade r as System.Web.UI.H tmlControls.Htm lHead;
if (header == null)
// cast failed...
else
// cast succeeded...
Best Regards,
Dustin Campbell
Developer Express Inc.
Nov 27 '06 #4

This works fine as well, but I think the previous example has preference
because it will only cast the object once.

Wiebe Tijsma

ni***********@i inet.net.au wrote:
You can also use the "is" keyword

System.Web.UI.H tmlControls.Htm lHead header;

if (this.PageHeade r is System.Web.UI.H tmlControls.Htm lHead)
{
header = (this.PageHeade r as
System.Web.UI.H tmlControls.Htm lHead);
}

On Nov 28, 7:58 am, "clintonG"
<csgallag...@RE MOVETHISTEXTmet romilwaukee.com wrote:
>Thanks...

<%= Clinton

"Dustin Campbell" <dust...@no-spam-pleasedevexpres s.comwrote in messagenews:c1* *************** **********@news .microsoft.com. ..
>>System.Web.UI .HtmlControls.H tmlHead header;
header = this.Page.Heade r as System.Web.UI.H tmlControls.Htm lHead;
if (header == null)
// cast failed...
else
// cast succeeded...
Best Regards,
Dustin Campbell
Developer Express Inc.
Nov 28 '06 #5
I am just curious on why you want to cast at all?

Gabriel Lozano-Morán

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com wrote in message
news:e5******** ******@TK2MSFTN GP02.phx.gbl...
Will somebody convert this for me...

System.Web.UI.H tmlControls.Htm lHead header;
header = TryCast(this.Pa ge.Header, System.Web.UI.H tmlControls.Htm lHead);

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-...8&z=17&l=0&m=h

Nov 28 '06 #6
Can somebody explain why this cast and this form of cast is used?

// An object named header is derived (?) from the class HtmlHead
System.Web.UI.H tmlControls.Htm lHead header;

// Using the is keyword this instance of the PageHeader object is typed
// as an HtmlHead object allowing the instance of this.PageHeader object
// to "borrow" properties of an HtmlHead object
this.PageHeader is System.Web.UI.H tmlControls.Htm lHead

I read the "is a" and the "has a" relationship but I don't understand
the "why a" and this is where I burn out.
<%= Clinton Gallagher
"Wiebe Tijsma" <wi*********@CA PITALStijsma.co mwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>
This works fine as well, but I think the previous example has preference
because it will only cast the object once.

Wiebe Tijsma

ni***********@i inet.net.au wrote:
>You can also use the "is" keyword

System.Web.UI. HtmlControls.Ht mlHead header;

if (this.PageHeade r is System.Web.UI.H tmlControls.Htm lHead)
{
header = (this.PageHeade r as
System.Web.UI. HtmlControls.Ht mlHead);
}

On Nov 28, 7:58 am, "clintonG"
<csgallag...@R EMOVETHISTEXTme tromilwaukee.co mwrote:
>>Thanks...

<%= Clinton

"Dustin Campbell" <dust...@no-spam-pleasedevexpres s.comwrote in
messagenews:c 1************** ************@ne ws.microsoft.co m...

System.Web.U I.HtmlControls. HtmlHead header;
header = this.Page.Heade r as System.Web.UI.H tmlControls.Htm lHead;
if (header == null)
// cast failed...
else
// cast succeeded...
Best Regards,
Dustin Campbell
Developer Express Inc.

Nov 28 '06 #7
In fact - the compiled msil is exactly the same but the example which
doesnt use "is" makes one extra read and write to the stack (tho not
being an expert in reading msil I couldnt tell you why)

try it :-)

On Nov 28, 11:51 am, Wiebe Tijsma <wiebeREM...@CA PITALStijsma.co m>
wrote:
This works fine as well, but I think the previous example has preference
because it will only cast the object once.

Wiebe Tijsma

nick.fletc...@i inet.net.au wrote:
You can also use the "is" keyword
System.Web.UI.H tmlControls.Htm lHead header;
if (this.PageHeade r is System.Web.UI.H tmlControls.Htm lHead)
{
header = (this.PageHeade r as
System.Web.UI.H tmlControls.Htm lHead);
}
On Nov 28, 7:58 am, "clintonG"
<csgallag...@RE MOVETHISTEXTmet romilwaukee.com wrote:
Thanks...
<%= Clinton
"Dustin Campbell" <dust...@no-spam-pleasedevexpres s.comwrote in messagenews:c1* *************** **********@news .microsoft.com. ..
>System.Web.UI. HtmlControls.Ht mlHead header;
header = this.Page.Heade r as System.Web.UI.H tmlControls.Htm lHead;
if (header == null)
// cast failed...
else
// cast succeeded...
Best Regards,
Dustin Campbell
Developer Express Inc.
Nov 28 '06 #8
I found the code in VB while trying to learn what options were available to
me to write into the head of the page when using Themes. I need to control
writing linked style sheets *after* the link element generated by the Theme.

<%= Clinton Gallagher

"Gabriel Lozano-Morán" <ab***@frontbri dge.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>I am just curious on why you want to cast at all?

Gabriel Lozano-Morán

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com wrote in message
news:e5******** ******@TK2MSFTN GP02.phx.gbl...
>Will somebody convert this for me...

System.Web.UI. HtmlControls.Ht mlHead header;
header = TryCast(this.Pa ge.Header, System.Web.UI.H tmlControls.Htm lHead);

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-...8&z=17&l=0&m=h


Nov 28 '06 #9
I picked up the code snippet from Accessing the Html Header in ASP.NET 2.0
[1]. I'm trying to make sense of how to use it when using Themes.

<%= Clinton Gallagher

[1] http://weblogs.asp.net/pscott/archiv...30/424039.aspx

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>I found the code in VB while trying to learn what options were available to
me to write into the head of the page when using Themes. I need to control
writing linked style sheets *after* the link element generated by the
Theme.

<%= Clinton Gallagher

"Gabriel Lozano-Morán" <ab***@frontbri dge.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>>I am just curious on why you want to cast at all?

Gabriel Lozano-Morán

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com wrote in
message news:e5******** ******@TK2MSFTN GP02.phx.gbl...
>>Will somebody convert this for me...

System.Web.UI .HtmlControls.H tmlHead header;
header = TryCast(this.Pa ge.Header, System.Web.UI.H tmlControls.Htm lHead);

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-...8&z=17&l=0&m=h



Nov 28 '06 #10

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

Similar topics

14
7244
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server running. I prefer not to. I just need Python components for local consumption in other languages. I remember Gnome libs having some thing like this....
2
3272
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. Javascritp has >>> and >>. >>> is a zero fill bit shift whereas >> is a sign propagating bit shift. My understanding is that the python >> is equivalent...
3
2283
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an ordinary Lisp S-expression. So it's easy enough to translate some XML into equivalent Lisp. Now I turn it over to the Lisp parser, which creates the...
1
3781
by: Vannela | last post by:
Is there any equivalent control in .NET for the Power builder DataWindow control? I am explaining the Datawindow architecture to some extent. Power Builder DataWindow Control has got different presentation styles and different data sources. Presentation styles like tabular format , graph format, grid format, freeform format, Composite...
7
3720
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s : String;
10
7314
by: karch | last post by:
How would this C# contruct be represented in C++/CLI? Or is it even possible? PolicyLevel level = (enumerator->Current) as PolicyLevel; Thanks, Karch
9
4034
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric equivalent. Is there such a function available in C#? I can see that VB.NET has one, but I couldn't see how to get at it in C#. For example, if I have...
14
2529
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if both statements are similar : *((char **)v)++ == *((char **)v++) Where v is a pointer to an array of characters,defined as char *v;
4
24559
by: =?Utf-8?B?TGVvIExleXM=?= | last post by:
Hi, The code below generates a compile error on line 3 (dim d...) Dim o As Object = "1900-01-01" Dim s As String = TryCast(o, String) Dim d As DateTime = TryCast(o, DateTime) The error is : TryCast operand must be reference type, but 'Date' is a value type.
0
7882
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8312
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6564
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1410
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1145
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.