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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:43:13+00:00 2026-05-11T03:43:13+00:00

I would like to do the following but I don’t think this will work:

  • 0

I would like to do the following but I don’t think this will work:

.OrderByDescending(s => Score(s)), ...   private double Score(Story s)         {             DateTime now = DateTime.Now;             TimeSpan elapsed = now.Subtract(s.PostedOn);             double daysAgo = elapsed.TotalDays;              return s.Votes.Count + s.Comments.Count - daysAgo;         } 

a. should this work? b. if not, do I need to query for the stories and then sort them by the score?

  • 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. 2026-05-11T03:43:13+00:00Added an answer on May 11, 2026 at 3:43 am

    Yes, that should work if the sequence is a sequence of Story items; what problem are you having? Note that if Score doesn’t apply to any instance, it might be worth making it static.

    Another option is to make the Score() method an instance method on a Story, or an extension method.

    Note that this only applies to LINQ-to-Objects; if you are using LINQ-to-SQL / LINQ-to-Entities, etc you either need to use a lambda for the whole thing, or (in LINQ-to-SQL only) use a UDF-mapped function (on the data-context) to calculate the value.

    Example (LINQ-to-Objects) with your original syntax:

    using System.Linq; using System; class Story { // declare type     public DateTime PostedOn { get; set; }     // simplified purely for convenience     public int VotesCount { get; set; }     public int CommentsCount { get; set; } } static class Program {     static void Main() {         // dummy data         var data = new[] {             new Story { PostedOn = DateTime.Today,                 VotesCount = 1, CommentsCount = 2},             new Story { PostedOn = DateTime.Today.AddDays(-1),                 VotesCount = 5, CommentsCount = 22},             new Story { PostedOn = DateTime.Today.AddDays(-2),                 VotesCount = 2, CommentsCount = 0}         };         var ordered = data.OrderByDescending(s=>Score(s));         foreach (var row in ordered)         {             Console.WriteLine(row.PostedOn);         }     }      private static double Score(Story s) {         DateTime now = DateTime.Now;         TimeSpan elapsed = now.Subtract(s.PostedOn);         double daysAgo = elapsed.TotalDays;         // simplified purely for convenience         return s.VotesCount + s.CommentsCount - daysAgo;     } } 

    Add a this (i.e. Score(this Story s)), and you can use:

    .OrderByDescending(s=>s.Score()) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know what exactly this feature is, but I would like to simulate
I would like to do something like the following but can't seem to get
Conceptually, I would like to accomplish the following but have had trouble understand how
Conceptually, I would like to accomplish the following but have had trouble understand how
I would like to do the equivalent of the following xaml in code, but
I would like to achieve the following but after days of trial I still
I have a route like following, ideally I would like it to match: domain.com/layout/1-slug-is-the-name-of-the-page
I would like to do something like the following: def add(a, b): #some code
I would like to do something like the following with spark. <viewdata model=IList[[string]] />
I would like to use something like the following: SELECT city FROM cities WHERE

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.