I think 5 is just a sample id. That URL is the equivalent of /Home/Details.aspx?id=5.
ShamWow
I think 5 is just a sample id. That URL is the equivalent of /Home/Details.aspx?id=5.
ShamWow
That's what I was looking for, thanks!
ShamWow
d@nish wrote:
As far as its equivalent is concerned, just see the IL through ILDAsm or reflector and it would make things a bit clear.
I know, but shamefully, I'm IL challenged. :)
ShamWow
d@nish wrote:
Why and when would you write a code like that?
When you're interested in keeping track of when "SomeCode" begins and ends -- for logging, profiling, etc.
ShamWow
Sounds logical, although I would imagine the compiler would also add an extra check for whether "disposable" is null inside the finally block. It's interesting that none of the examples you see out there for the using
statement ever mention that if you don't assign your IDisposable type to an explicitly declared variable, the compiler will do it for you behind the scenes. Thanks.
ShamWow
Thanks for the quick response, but that article doesn't address my specific example where a variable is not explicitly declared inside the using statement.
ShamWow
I've been looking around for an answer to this puzzling question, but so far no luck: What's the compiler's try/finally
equivalent of this code:
using (new SomeIDisposableClass())
{
SomeCode();
}
Thanks!
ShamWow
J. Dunlap wrote:
you might as well use the LINQ syntax.
I don't like LINQ syntax. It's like they shoehorned SQL syntax into C#, unnecessarily. I prefer this a lot more:
return things.Where(id => IsAllowed(id))
.Select(id => new Something(id))
.ToList();
ShamWow
Rob Graham wrote:
Refactoring to add cleverness?
Nothing wrong with more cleverness. That's what makes LINQ so appealing.
Rob Graham wrote:
I don't see the value here
The list is not passed into the sub-method each time. That's where I see the value.
ShamWow
Simon Stevens wrote:
I don't see how the re factored version adds any value.
The list does not need to be passed into the method each time. That's the value I see.
Simon Stevens wrote:
If anything it removes the possibility of re-using that bit of code in the private method elsewhere in the class.
Sure, but this is a case where it won't be used anywhere else.
ShamWow
Dave Parker wrote:
Prefer the original personally, more readable
I agree -- I'm still not used to reading C# code with methods declared inside methods.
Dave Parker wrote:
I don't think the lambda is really adding any value.
The value I see is that it avoids having to repeatedly pass the collection into the method. That's my biggest reason for favoring this approach.
ShamWow
I love it! :laugh: Actually, it does go too far -- more than anything because it wastes memory... but I can't help admiring the power of LINQ.
ShamWow
I was going through some C# code I had recently written, when I spotted a cool way to refactor it. See if you agree: BEFORE:
public IList<Something> GetSomethings()
{
var list = new List<Something>();
AddIfAllowed(list, SomeId.Table);
AddIfAllowed(list, SomeId.Chair);
AddIfAllowed(list, SomeId.House);
AddIfAllowed(list, SomeId.Car);
return list;
}
private void AddIfAllowed(ICollection<Something> list, SomeId id)
{
if (IsAllowed(id))
list.Add(new Something {Id = id});
}
AFTER:
public IList<Something> GetSomethings()
{
var list = new List<Something>();
Action<SomeId> addIfAllowed = id =>
{
if (IsAllowed(id))
list.Add(new Something {Id = id});
};
addIfAllowed(SomeId.Table);
addIfAllowed(SomeId.Chair);
addIfAllowed(SomeId.House);
addIfAllowed(SomeId.Car);
return list;
}
:cool:
ShamWow
Intel 4004 wrote:
Obama has got to go, no doubt about it.
He will... in about 8 years. :laugh:
ShamWow
There's a missing scene there, right before the last one. It shows Bobby laying off the old lady after he realizes outsourcing her job will make him a lot richer.
ShamWow
Chris Austin wrote:
It is a pity it has taken a deficit fueled by a liberal act of nation building, an obscene lack of political and corporate ethics, and a change in political fortunes for people like you to opt for the red pill.
Well said, but unfortunately he's just another whiny sore loser. It's very doubtful he would have complained about this incident had McCain won the election.
ShamWow
kmg365 wrote:
chant anti-Obama (anti-Makulski, anti-Cardin, anti-Hoyer) slogans.
Just out of curiousity, do you make more than $250,000 a year?
ShamWow
Gary Kirkham wrote:
Jesus loves you, why do you keep rejecting Him?
Because I'm not gay.
ShamWow
Gary Kirkham wrote:
My sig is what?
a sham. Wow.
ShamWow
Marc Clifton wrote:
I would say they are the foundation of all that is bad with TV
But what's so bad about being a rich good-looking guy who gets to spend time with other rich good looking people to talk about their feelings for each other? :rolleyes:
ShamWow