Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6731875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:34:51+00:00 2026-05-26T10:34:51+00:00

Ciao everyone, i was finally able to switch from .NET Framework 2.0 to .NET

  • 0

Ciao everyone,
i was finally able to switch from .NET Framework 2.0 to .NET Framework 4.0.

I am trying to get some experience about lambda expression and LINQ.

Is it possible to translate this:

for (int cont = 0;cont < args.Length; cont++)
    Console.WriteLine("#" + cont + " " + "<" + args + ">");

into a single line lambda expression,or using LINQ, or even some other costruct i am no aware of ?
Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:34:52+00:00Added an answer on May 26, 2026 at 10:34 am

    LINQ operations shouldn’t have side effects or do actions. They should only be used to produce, from a IEnumerable<T> another IEnumerable<T> (or from a IQueryable<T> another IQueryable<T> or IEnumerable<T>) (or if aggregating, like .Max, .All… a single result)

    Read for example http://blogs.msdn.com/b/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx.

    (and note that this question is quite asked on SO… Read for example my reply here ToList().ForEach in Linq and see a solution to a similar problem)

    Now, if you hate yourself enough, you can do this:

    strs.Select((p, index) =>
    {
        Console.WriteLine("#" + index + " " + "<" + p + ">");
        return true;
    }).All(p => p);
    

    We are using the .All(p => p) to “materialize” the Select operation. This because Select is “lazy” and won’t be executed if no one cycles it.

    Technically you could even try to obfuscate it a little:

    strs.Select((p, index) =>
    {
        Console.WriteLine("#" + index + " " + "<" + p + ">");
        return false;
    }).Any(p => p);
    

    (All checks that all the elements are true and stops if one of the is false, so it has to cycle all of them (because we always return true;). Any (as written) checks that at least one of the elements is true and then stops (but all of our elements are false, becasue we do return false; so the Any will cycle all the elements)

    Now… The advantage of these techniques over using ToList is that we aren’t “duplicating” an Array to a List<T> just to use a “wrong” method of List<T>. If the ForEach method of List<T> is “wrong”, duplicating an Array to a List just to use it is doubly-wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to discuss about a problem: i've lately had discussions with some customers
ciao everybody, I am becoming stupid about this question. I hope someone can help
Can I get from PHP a value back like the new id from the
I have an html page with this code <object data=ciao.xhtml width=100% height=100% type=application/xhtml+xml> </object>
I am trying to connect a dojo 1.7 objectStore or itemFileWriteStore to a grid
It seems it's always empty : var idStruttura=2; var arrayMarkers=new Array(); arrayMarkers[sede_+idStruttura] = ciao;
i have to modify an asp.net application. The app consists of an huge gridview
for security reasons i want the users on my website not to be able
Some agents in an ancient Lotus Notes application has a difference in agent-enabled behaviour
I'm trying to do a bbcode parser class that can create personalyzed tags, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.