Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

Al Beback

@Al Beback
About
Posts
897
Topics
17
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Asp.Net MVC2 in VS 2010
    A Al Beback

    I think 5 is just a sample id. That URL is the equivalent of /Home/Details.aspx?id=5.

    ShamWow

    C# csharp asp-net visual-studio question

  • using statement equivalent
    A Al Beback

    That's what I was looking for, thanks!

    ShamWow

    C# question

  • using statement equivalent
    A Al Beback

    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

    C# question

  • using statement equivalent
    A Al Beback

    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

    C# question

  • using statement equivalent
    A Al Beback

    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

    C# question

  • using statement equivalent
    A Al Beback

    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

    C# question

  • using statement equivalent
    A Al Beback

    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

    C# question

  • Refactoring C#, Javascript style.
    A Al Beback

    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

    The Lounge csharp javascript code-review

  • Refactoring C#, Javascript style.
    A Al Beback

    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

    The Lounge csharp javascript code-review

  • Refactoring C#, Javascript style.
    A Al Beback

    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

    The Lounge csharp javascript code-review

  • Refactoring C#, Javascript style.
    A Al Beback

    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

    The Lounge csharp javascript code-review

  • Refactoring C#, Javascript style.
    A Al Beback

    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

    The Lounge csharp javascript code-review

  • Refactoring C#, Javascript style.
    A Al Beback

    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

    The Lounge csharp javascript code-review

  • What a Catastrophe
    A Al Beback

    Intel 4004 wrote:

    Obama has got to go, no doubt about it.

    He will... in about 8 years. :laugh:

    ShamWow

    The Back Room html com question

  • The explanation
    A Al Beback

    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

    The Back Room com

  • Freedom of speech
    A Al Beback

    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

    The Back Room html

  • T(taxed) E(enough) A(already) aka TEA Parties
    A Al Beback

    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

    The Back Room com question

  • This is disgusting [modified]
    A Al Beback

    Gary Kirkham wrote:

    Jesus loves you, why do you keep rejecting Him?

    Because I'm not gay.

    ShamWow

    The Back Room

  • This is disgusting [modified]
    A Al Beback

    Gary Kirkham wrote:

    My sig is what?

    a sham. Wow.

    ShamWow

    The Back Room

  • After 72 years...
    A Al Beback

    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

    The Lounge
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups