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 8496995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:00:07+00:00 2026-06-11T00:00:07+00:00

[WebMethod(Description = Return all activities by Task.)] public IList<ActivityDto> GetActivitiesByTaskID(int taskID) { IList<Activity> activities

  • 0
[WebMethod(Description = "Return all activities by Task.")]
public IList<ActivityDto> GetActivitiesByTaskID(int taskID)
{
    IList<Activity> activities = ActivityDao.GetByTaskID(taskID);
    IList<ActivityDto> activityDtos = new List<ActivityDto>(activities.Count);

    foreach(Activity activity in activities)
        activityDtos.Add(ActivityDto.Create(activity));

    return activityDtos;
}

shortened to:

[WebMethod(Description = "Return all activities by Task.")]
public IList<ActivityDto> GetActivitiesByTaskID(int taskID)
{
    return ActivityDao.GetByTaskID(taskID).Select(ActivityDto.Create).ToList();
}

I feel like because I have to ask — it probably is doing a bit too much. The only part that causes me any concern, though, is passing the function to the Select statement. I think that I have just not used that syntax enough, though, and that it’s actually quite a nifty way of expressing a lot succinctly.

I’d like to know if fellow programmers would be upset seeing the shortened version of this method.

EDIT: Also, comments on efficiency comparison would be appreciated. I know LINQ is notorious for working slower on large data sets. I would say 10,000-20,000 records could be enumerated in some instances.

  • 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-06-11T00:00:09+00:00Added an answer on June 11, 2026 at 12:00 am

    No, it is expressive and concise.

    The first version is all about how to iterate over Lists and transform the elements.

    The second version is all about what the result should be.

    LINQ was created to give us powerful, readable tools for working with collections and transforming them. That’s exactly what you’re using it for in the second example.

    For people unfamiliar with the method group syntax, another option might be to use a query expression:

    var result = from task in ActivityDao.GetByTaskID(taskID)
                 select ActivityDto.Create(task);
    return result.ToList(); // if you really need it as a list
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've got the following simple webservice : [WebMethod()] public int Add(int a) { return
Code Behind: [WebMethod] public static string emp() { return BlaBla; } Aspx Page: $(document).ready(function()
I have following webservice: [webmethod] public string MakeReservation(?? PassengersInfo)//what data type use for PassengerInfo
I had a webmethod working which returned a byte array to the caller: public
I have a standard webservice in ASP .Net 4.0 defined like this: [WebMethod] public
I have written my webmethod in aspx.cs file , but when i call n.Nautilus()
From within a webmethod (.net asmx file) - is it possible to determine from
I am calling a WebMethod from this code: if($(this).attr(checked)) { .. MyWebMethod(variable1, variable2, onSuccessFunction);
I've created a [WebMethod] on ASP.NET Web Service which reads XML documents from different
I want to expose a webmethod that will take in a username and password

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.