<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C#</title><link>http://forums.asp.net/37.aspx</link><description>Discussions/Questions about the C# language. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=13&amp;c=23" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: VB.net to C#</title><link>http://forums.asp.net/thread/3269735.aspx</link><pubDate>Wed, 01 Jul 2009 19:39:38 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269735</guid><dc:creator>JeffreyABecker</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269735.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3269735</wfw:commentRss><description>&lt;p&gt;1)&lt;br /&gt;&lt;br /&gt;C# requires that you explicitly convert types for everything but converions to base classes.&amp;nbsp; The error you&amp;#39;re getting is the compiler telling you that you&amp;#39;ve violated this rule. &amp;nbsp;&lt;br /&gt;&lt;br /&gt;If the DataSet can return null, what should the value of your _id field be when it does? (as an asside why are you ever having an ID that is nullable?)&amp;nbsp; If you need to store a null in there, I suggest declaring it as a Nullable&amp;lt;Guid&amp;gt; rather than just a Guid.&amp;nbsp; In this case you can reference System.Data.DatasetExtensions in your project and use the following:&lt;br /&gt;&lt;br /&gt;_id = dr.Field&amp;lt;Nullable&amp;lt;Guid&amp;gt;&amp;gt;(&amp;quot;ID&amp;quot;);&lt;br /&gt;_title = dr.Field&amp;lt;string&amp;gt;(&amp;quot;title&amp;quot;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;2)&lt;br /&gt;do as such&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;dothis(&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;a,&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;b,&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;c);&lt;br /&gt;Since linefeeds arent statement terminators in C#, you dont need any special syntax for continuing a statement on the next line.&amp;nbsp; the compiler sees a linefeed just like it sees a space.&lt;br /&gt;&lt;br /&gt;3) No, but many of the uses of with statements can be simulated using the object initializer syntax&lt;/p&gt;</description></item><item><title>Re: VB.net to C#</title><link>http://forums.asp.net/thread/3269669.aspx</link><pubDate>Wed, 01 Jul 2009 19:06:24 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269669</guid><dc:creator>JsonTerre1</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269669.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3269669</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;2 more questions on this. &lt;/p&gt;
&lt;p&gt;How do you handle DateTimes with this. You don&amp;#39;t want to set a member of type DateTime to a value that is not a datetime. A string can be string.Empty. Do i just set the DateTime to Nothing or is there something else i shoudl do?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;j&lt;/p&gt;</description></item><item><title>Re: VB.net to C#</title><link>http://forums.asp.net/thread/3269639.aspx</link><pubDate>Wed, 01 Jul 2009 18:48:55 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269639</guid><dc:creator>JsonTerre1</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269639.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3269639</wfw:commentRss><description>&lt;p&gt;How would this work&amp;nbsp;for a guid?&amp;nbsp;Convert.IsDBNull(dr[&amp;quot;ID&amp;quot;]) ? string.Empty : Convert.ToString(dr[&amp;quot;ID&amp;quot;]);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;------&lt;/p&gt;
&lt;p&gt;i got it&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;_ID&amp;nbsp; = Convert&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.IsDBNull(dr[&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;ID&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;]) ? &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Guid&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Empty : (&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Guid&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)dr[&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;ID&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;];&lt;/font&gt;&lt;/p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;thanks again&lt;/p&gt;
&lt;p&gt;j&lt;/p&gt;</description></item><item><title>Re: VB.net to C#</title><link>http://forums.asp.net/thread/3269613.aspx</link><pubDate>Wed, 01 Jul 2009 18:40:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269613</guid><dc:creator>RemithR</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269613.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3269613</wfw:commentRss><description>&lt;p&gt;1) use Convert.IsDBNull to check for DBNull&lt;/p&gt;
&lt;p&gt;_id = Convert.IsDBNull(dr[&amp;quot;ID&amp;quot;]) ? string.Empty : Convert.ToString(dr[&amp;quot;ID&amp;quot;]);&lt;/p&gt;
&lt;p&gt;_title = Convert.IsDBNull(dr[&amp;quot;title&amp;#39;]) ? string.Empty : Convert.ToString(dr[&amp;quot;title&amp;#39;]);&lt;/p&gt;
&lt;p&gt;2) use without _&lt;/p&gt;
&lt;p&gt;dothis(&lt;br /&gt;a,&lt;br /&gt;b,&lt;br /&gt;c)&lt;/p&gt;
&lt;p&gt;3) please refer to &lt;a href="http://msdn.microsoft.com/en-us/vcsharp/aa336816.aspx"&gt;http://msdn.microsoft.com/en-us/vcsharp/aa336816.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;VB&lt;br /&gt;With Button1&lt;br /&gt;&amp;nbsp; .Text = &amp;quot;Hello&amp;quot;&lt;br /&gt;&amp;nbsp; .BackColor = Color.Blue&lt;br /&gt;End With&lt;/p&gt;
&lt;p&gt;c#&lt;br /&gt;Button1.Text = &amp;quot;Hello&amp;quot;&lt;br /&gt;Button1.BackColor = Color.Blue&lt;/p&gt;</description></item><item><title>Re: VB.net to C#</title><link>http://forums.asp.net/thread/3269581.aspx</link><pubDate>Wed, 01 Jul 2009 18:24:08 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269581</guid><dc:creator>RatheeshC</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269581.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3269581</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Try this&lt;br /&gt;1.&lt;br /&gt;if (dr[&amp;quot;ID&amp;quot;] != null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _id = dr[&amp;quot;ID&amp;quot;].ToString();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (dr[&amp;quot;title&amp;quot;] != null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _title = dr[&amp;quot;title&amp;quot;].ToString();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;2.replace the _ by +&lt;/p&gt;
&lt;p&gt;dothis(+&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&amp;quot;a&amp;quot;, +&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&amp;quot;b&amp;quot;, +&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&amp;quot;c&amp;quot;);&lt;/p&gt;
&lt;p&gt;3.&lt;br /&gt;try use using statement&lt;/p&gt;</description></item><item><title>VB.net to C#</title><link>http://forums.asp.net/thread/3269528.aspx</link><pubDate>Wed, 01 Jul 2009 17:55:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269528</guid><dc:creator>JsonTerre1</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269528.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3269528</wfw:commentRss><description>&lt;p&gt;I am in the&amp;nbsp;process of converting some applications to C# by request of a client. I am new to C# so and have&amp;nbsp;been stumped on some things. This is VS 3.5.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I have a datarow that has a value in the ID column(Guid) and Title column (String).&amp;nbsp;I am trying to set variables of the same type to the values of the datarow columns like so:&lt;/p&gt;
&lt;p&gt;_id = dr[&amp;quot;ID&amp;#39;]&lt;/p&gt;
&lt;p&gt;_title = dr[&amp;quot;title&amp;quot;]&lt;/p&gt;
&lt;p&gt;i am getting an error when building. Cannot implicitly convert type &amp;#39;object&amp;#39; to &amp;#39;Guid&amp;#39;. An explicit conversion exists (are you missing a cast?). Since the type is a uniqueidentifier (guid) from the query would that error converting guid to guid? There are times that the result set returns NULL so i don;t want to cast it. That would cause an error.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In vb.net you can call a function and pass params in like so:&lt;/p&gt;
&lt;p&gt;dothis( _&lt;/p&gt;
&lt;p&gt;a, _&lt;/p&gt;
&lt;p&gt;b, _&lt;/p&gt;
&lt;p&gt;c)&lt;/p&gt;
&lt;p&gt;in c# it won;t let you. You have to place them in a long string. I find that breaking the params into seperate lines is easier to read when you have some methods that have 20 or 30 params. is there an equivalent to this in c#?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Is there an equivalent to the WithStatement in c#?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;thanks all&lt;/p&gt;
&lt;p&gt;j&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>