Click here to Skip to main content
15,904,416 members
Home / Discussions / C#
   

C#

 
GeneralRe: Interfacing Machines with LIS from Scratch Pin
Simon_Whale15-Jan-14 5:47
Simon_Whale15-Jan-14 5:47 
GeneralRe: Interfacing Machines with LIS from Scratch Pin
Ron Beyer15-Jan-14 5:53
professionalRon Beyer15-Jan-14 5:53 
GeneralRe: Interfacing Machines with LIS from Scratch Pin
Ravi Bhavnani15-Jan-14 6:26
professionalRavi Bhavnani15-Jan-14 6:26 
GeneralRe: Interfacing Machines with LIS from Scratch Pin
Dave Kreskowiak15-Jan-14 6:57
mveDave Kreskowiak15-Jan-14 6:57 
GeneralRe: Interfacing Machines with LIS from Scratch Pin
max carter15-Jan-14 8:11
max carter15-Jan-14 8:11 
GeneralRe: Interfacing Machines with LIS from Scratch Pin
Eddy Vluggen15-Jan-14 6:24
professionalEddy Vluggen15-Jan-14 6:24 
GeneralRe: Interfacing Machines with LIS from Scratch Pin
Bernhard Hiller15-Jan-14 21:22
Bernhard Hiller15-Jan-14 21:22 
QuestionAudio recorder in c# Pin
Member 865071615-Jan-14 1:55
Member 865071615-Jan-14 1:55 
AnswerRe: Audio recorder in c# Pin
Pete O'Hanlon15-Jan-14 2:56
mvePete O'Hanlon15-Jan-14 2:56 
AnswerRe: Audio recorder in c# Pin
BillWoodruff15-Jan-14 5:18
professionalBillWoodruff15-Jan-14 5:18 
QuestionHow to get Device list in emgu Pin
Kkouer14-Jan-14 22:06
Kkouer14-Jan-14 22:06 
AnswerRe: How to get Device list in emgu Pin
Richard MacCutchan14-Jan-14 22:35
mveRichard MacCutchan14-Jan-14 22:35 
GeneralRe: How to get Device list in emgu Pin
Kkouer14-Jan-14 22:55
Kkouer14-Jan-14 22:55 
QuestionC# bound column in datagridview Pin
John Malcosky14-Jan-14 11:51
John Malcosky14-Jan-14 11:51 
AnswerRe: C# bound column in datagridview Pin
GuyThiebaut14-Jan-14 22:06
professionalGuyThiebaut14-Jan-14 22:06 
AnswerRe: C# bound column in datagridview Pin
GuyThiebaut16-Jan-14 6:20
professionalGuyThiebaut16-Jan-14 6:20 
AnswerRe: C# bound column in datagridview Pin
Rahul VB31-Jan-14 7:21
professionalRahul VB31-Jan-14 7:21 
QuestionLINQ / lambda expression to check if date is within a range Pin
littleGreenDude14-Jan-14 4:59
littleGreenDude14-Jan-14 4:59 
AnswerRe: LINQ / lambda expression to check if date is within a range Pin
OriginalGriff14-Jan-14 5:08
mveOriginalGriff14-Jan-14 5:08 
GeneralRe: LINQ / lambda expression to check if date is within a range Pin
littleGreenDude14-Jan-14 5:15
littleGreenDude14-Jan-14 5:15 
GeneralRe: LINQ / lambda expression to check if date is within a range Pin
Dave Kreskowiak14-Jan-14 5:26
mveDave Kreskowiak14-Jan-14 5:26 
GeneralRe: LINQ / lambda expression to check if date is within a range Pin
OriginalGriff14-Jan-14 5:36
mveOriginalGriff14-Jan-14 5:36 
AnswerRe: LINQ / lambda expression to check if date is within a range Pin
Pete O'Hanlon14-Jan-14 5:20
mvePete O'Hanlon14-Jan-14 5:20 
Hopefully, this will give you some idea as to how to do this:
C#
using System;
using System.Collections.Generic;
using System.Linq;

namespace LinqDateTest
{
    class Program
    {
        private readonly Dictionary<string, MySimpleClass> _mySimpleClasses = new Dictionary<string, MySimpleClass>();
        static void Main(string[] args)
        {
            new Program().AllocAndTest();
        }

        private int _index = 1;
        public void AllocAndTest()
        {
            Alloc("10/03/2024");
            Alloc("10/12/2013");
            Alloc("11/12/2013");
            Alloc("12/12/2013");

            var results = (from p in _mySimpleClasses
                          let myDate = DateTime.Parse(p.Value.MyStringDate)
                          where myDate > DateTime.Now.Subtract(TimeSpan.FromDays(100)) && myDate < DateTime.Now
                          select p.Value).ToList();
            foreach (var value in results)
            {
                Console.WriteLine("Index {0}, Value {1}", value.Index, value.MyStringDate);
            }

            Console.Read();
        }

        private void Alloc(string dateValue)
        {
            _mySimpleClasses.Add(dateValue, new MySimpleClass { MyStringDate = dateValue, Index = _index++ });
        }
    }

    public class MySimpleClass
    {
        public string MyStringDate;
        public int Index;
    }
}
Saying that, I really wouldn't like to push the idea of using a string to represent the date. If the string value isn't parseable using Parse, the whole Linq query will blow up. A simple extension will take care of this:
C#
public static class DateExtensions
{
    public static DateTime ToSafeDate(this string value)
    {
        DateTime parsedDate;
        if (!DateTime.TryParse(value, out parsedDate))
        {
            parsedDate = DateTime.MinValue;
        }
        return parsedDate;
    }
}
This would turn the Linq query into:
C#
var results = (from p in _mySimpleClasses
              let myDate = p.Value.MyStringDate.ToSafeDate()
              where myDate > DateTime.Now.Subtract(TimeSpan.FromDays(100)) && myDate < DateTime.Now
              select p.Value).ToList();

QuestionBinding Navigator is disabled with empty List<T> Pin
Mondis14-Jan-14 3:09
Mondis14-Jan-14 3:09 
AnswerRe: Binding Navigator is disabled with empty List<T> Pin
Dave Kreskowiak14-Jan-14 5:19
mveDave Kreskowiak14-Jan-14 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.