Solved

Turn this into Linq

Posted on 2014-03-03
5
186 Views
Last Modified: 2016-02-10
Can this be turned into Linq to make it less ugly?


if (_now > DateTime.Today && _now < DateTime.Today.AddHours(10).AddMinutes(30))
                        {
                            _medPass = "AM";

                            ts = slots.GetSlot(TimeSlotType.AM);
                            MainForm.CurrentInstance.ShowMedPass(ts, MedPassMode.NORMAL, CartGroup.Med, patient);
                            break;
                        }

                        else if (_now > DateTime.Today.AddHours(10).AddMinutes(30) &&
                                 _now < DateTime.Today.AddHours(13).AddMinutes(30))
                        {
                            _medPass = "NOON";

                            ts = slots.GetSlot(TimeSlotType.NOON);
                            MainForm.CurrentInstance.ShowMedPass(ts, MedPassMode.NORMAL, CartGroup.Med, patient);
                            break;
                        }

                        else if (_now > DateTime.Today.AddHours(13).AddMinutes(30) &&
                                 _now < DateTime.Today.AddHours(18).AddMinutes(59))
                        {
                            _medPass = "PM";

                            ts = slots.GetSlot(TimeSlotType.PM);
                            MainForm.CurrentInstance.ShowMedPass(ts, MedPassMode.NORMAL, CartGroup.Med,
                                patient);
                            break;
                        }

Open in new window

0
Comment
Question by:rawinnlnx9
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39900743
What do you think LINQ was designed to do? (I'm not trying to be a smart-ass; I really want to understand what you know about LINQ!)
0
 
LVL 9

Author Comment

by:rawinnlnx9
ID: 39900771
I'm actually trying to learn it. I want to figure out a way to use the FirstOrDefault to improve the query and get rid of the if/elseif. I think that there's a more elegant way to do this but my attemps have been tossed out as rubbish by the compiler.

Aside from that I don't know how else to answer your question. Linq is new to me and I need to start using it more.
0
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 0 total points
ID: 39900838
Figured it out. C# does the heavy lifting for you if you just ask nicely.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39900851
No worries. The reason I asked was because nothing in your code jumped out at me as being LINQ-friendly. But I attribute that more to not knowing the types of each object rather than your code structure. LINQ can be a bit of fun when you get to the more advanced features of it. Keep at it  = )
0
 
LVL 9

Author Closing Comment

by:rawinnlnx9
ID: 39914450
I answered it myself. What other grade would I give?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now