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
Solved

Turn this into Linq

Posted on 2014-03-03
5
195 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Player 2017 5 35
Hey!! 5 36
Problem with SelectList in .NET MVC application 1 26
custom authorization on controller action and HTML in asp.net mvc 1 21
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…

790 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