[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Turn this into Linq

Posted on 2014-03-03
5
Medium Priority
?
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

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 75

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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