gimme a "with" keyword in C#http://forums.asp.net/t/61373.aspx/1?gimme+a+with+keyword+in+C+Mon, 09 Mar 2009 14:48:43 -04006137361373http://forums.asp.net/p/61373/61373.aspx/1?gimme+a+with+keyword+in+C+gimme a "with" keyword in C# i think the with contruct is sorely missing in c#. 2002-10-02T17:52:40-04:0064511http://forums.asp.net/p/61373/64511.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# i would also like to have this 2002-10-08T15:28:10-04:0067472http://forums.asp.net/p/61373/67472.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# How would you expect to use it? 2002-10-13T22:09:13-04:0067746http://forums.asp.net/p/61373/67746.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# similar to VB. for example (VB): with response .write(&quot;some text&quot;) .write(vbnewline) .end end with i suppose the C# version would look something like: with response { .write(&quot;some text&quot;); .write(vbnewline); .end; } ...i also like VB's use of the &quot;!&quot; in such a manner: response.write request.querystring.item(&quot;page&quot;) ...can also be coded as: response.write request.querystring!page i just learned this one a couple months ago. its pretty cool IMO. 2002-10-14T12:37:49-04:0067750http://forums.asp.net/p/61373/67750.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# ThisHereThing thing = new ThisHereThing(); with (thing) { .DoSomething(); .Arity = 8; } OR with (new ThisHereThing()) { .DoSomething(); .Arity = 8; } with or without the leading periods. see vb or javascript. 2002-10-14T12:41:24-04:0067800http://forums.asp.net/p/61373/67800.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# Well I see why you might like it (especially if you liked it in VB), but I hate that feature. I know you might say, &quot;then avoid it,&quot; but it's not always the case that you're working with YOUR code. 2002-10-14T13:48:34-04:0068462http://forums.asp.net/p/61373/68462.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# just fyi... check out GotDotNet.com, Eric Gunnerson has an excellent response there why C# doesn't have the With keyword. hth, dave 2002-10-15T13:28:30-04:0069123http://forums.asp.net/p/61373/69123.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# can you provide a link to the Gunnerson article? 2002-10-16T12:45:18-04:0072554http://forums.asp.net/p/61373/72554.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# &quot;with&quot; is a dirty feature, and makes code confusing and strange looking. I did a bunch of work in VB, and used it myself. However, I found that it really doesn't save time. I agree the feature should be available, but I would say only use it when you really really really need it, which should be never. 2002-10-22T14:15:06-04:0073194http://forums.asp.net/p/61373/73194.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# i've also done a bunch of work in VB and found the feature to be quite useful, especially when considering its use similar to the &quot;using&quot; construct. we used it with much success and developed ways to streamline code, making it more maintainable in the process. what i see being posted are preferences, roughly equivalent to the fight between curly braces on the same line or starting below. since i write the coding standards for my team, i ultimately get to choose. 2002-10-23T12:54:08-04:00101007http://forums.asp.net/p/61373/101007.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# I have been looking for this article as well... Do you have a link? 2002-12-08T04:43:31-05:00520923http://forums.asp.net/p/61373/520923.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a with keyword in C# okay, now i'm a convert. i just had to read through some very poor vb code, scrolling through pages and pages of code within one With block (including nested With blocks). even if people could write their code better, i think i'd still prefer that the thing didn't exist. it just encourages sloppiness. 2004-03-26T21:25:03-05:00521080http://forums.asp.net/p/61373/521080.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a with keyword in C# Hah. There is a technical difference between what with does and using. With is a shortcut, but using is not. <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfusingstatement.asp"> Here is what using is</a>. <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfusingstatement.asp"> With block</a>. 2004-03-27T02:00:51-05:00528926http://forums.asp.net/p/61373/528926.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a with keyword in C# hlaford, I'm sure we can look through your C# code and find sloppiness. As we can everywhere. That sounds like an extreme case. I've never encountered such a &quot;sloppy&quot; long list of &quot;with's&quot; and nested withs that I have lost any productivity over. But then, inheritence and generics and other C# features can just as easily be abused. But we don't see people crying that they shouldn't exist. Thanks, Shawn 2004-04-02T16:19:51-05:00528932http://forums.asp.net/p/61373/528932.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a with keyword in C# picky, There's nothing wrong with a &quot;shortcut&quot;, either. Nothing wrong with being more productive. I fail to see how copy and pasting a long reference path is more productive, espeicially in the cases when I have something else I want to paste then I have to click and scroll around and copy again what I want and paste it and lose more productivity to do so. I also fail to see how assigning a reference object is better than a &quot;With&quot;... because then the code just gets littered with all kinds of temporary reference variables declarations and such. It just isn't clean, in my experience. It's a far better solution to just type in the full path from a readibility perspective but then it is more expensive because it seems to look up the reference each time it is listed as opposed to the ugly reference object method which only looks up the references once and as opposed to the much cleaner with approach which would presumably also only look it up once. I've even looked at the IL and the dissassembled code of a VB.NET With statement and it is indeed optimized (which directly contradicts the arguments of some who say it was only an optimization in VB6). 2004-04-02T16:24:54-05:00529066http://forums.asp.net/p/61373/529066.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a with keyword in C# i promoted the same philosophy before, but i've changed my tune. i think it works well in a codebase that focuses on clarity and brevity. if i have a method that is screens long, there shouldn't be an all-encompassing With block. by the time i get to any meat, the object using the With scope has long scrolled off the page. temporary, explanatory variables are _always_ good if the developer bothers to use a meaningful name. i've long since lost any feeling of need for With. 2004-04-02T18:16:50-05:00531836http://forums.asp.net/p/61373/531836.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a with keyword in C# leabre, I didn't pick a side. I was defining the two terms because they should not be used interchangeably, at all. The point of the using statement is to be able to call the destructor immediately following the } of the using statement. 2004-04-05T23:34:08-04:002992635http://forums.asp.net/p/61373/2992635.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# <p>I miss this a lot ... but i thought on this and found out that there might be a VALID reason behind this....i mean think of this situation</p> <p>with(firstVar)</p> <p>{</p> <p>&nbsp;with(secondVar)</p> <p>{</p> <p>&nbsp;.SimilarPropertyInbothVars? </p> <p>//Ofcource you will qualify?<br> </p> <p>} <br> </p> <p>} </p> <p>&nbsp;</p> <p>//</p> <p>and i dont think this is dirty coding..... there are two more things C# has given like</p> <p>Item newitem = new Item{</p> <p>&nbsp;Prop = &quot;value&quot;,</p> <p>Prop2 = 34 <br> </p> <p>}; </p> <p>and&nbsp;</p> <p>using(object = new object())</p> <p>{</p> <p>&nbsp;//work</p> <p>} </p> <p>//obj discarded from GC ?</p> <p>&nbsp;</p> <p>...............................</p> <p>MORE:- it seems like the case when you have implemented two interfaces and then you must Qualify the method names which are similar?</p> <p>&nbsp;</p> <p>.. because there is complexity so MIGHT be possible that MS missed it</p> <p>but anyhow.</p> <p>&nbsp;I'm still missing &quot;with&quot;</p> <p>&nbsp;</p> <p>thanks <br> </p> 2009-03-09T10:35:48-04:002992645http://forums.asp.net/p/61373/2992645.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# <p>&nbsp;btw if you use unqualified properties in nested With statement. then it would be the dirtiest code. agreed<br> </p> 2009-03-09T10:40:34-04:002992690http://forums.asp.net/p/61373/2992690.aspx/1?Re+gimme+a+with+keyword+in+C+Re: gimme a "with" keyword in C# <p>IMHO with is a very beautiful feature of VB.Net.<br> It reduces the typing of the given object to some extent...</p> 2009-03-09T10:58:25-04:00