C# Complete Tutorials – 37 – Enumerations [w/ subs]



00:00:00 – in this video we are going to talk about
00:00:03 – enumerations so but before we do that I
00:00:06 – will show you one modification can make
00:00:08 – the visual studio to make it perhaps a
00:00:10 – little more helpful so if you go to
00:00:11 – tools what is that right now with this
00:00:14 – program that CS across the top is just a
00:00:17 – line that we can type on but if you go
00:00:19 – to tools and options and you go through
00:00:22 – text editor like this so sort of like
00:00:26 – text editor and I'm going to see sharp
00:00:28 – and you see where it says navigation bar
00:00:31 – and select that and then click OK and
00:00:35 – that gives you a box see that you can
00:00:38 – allow you to look inside a project you
00:00:39 – see now look very carefully at that box
00:00:41 – as we type because the other box is to
00:00:44 – the right of it the dropdowns will also
00:00:46 – become populated so that's what they
00:00:49 – call the navigation bar all right so big
00:00:52 – idea with numeration with those
00:00:53 – enumerations allow us to create list of
00:01:00 – named constants like that again instead
00:01:04 – of for example saying day one day to
00:01:06 – make me you can say Monday Tuesday and
00:01:11 – so unless you can give meaningful names
00:01:14 – to Constance all right so take a look at
00:01:17 – this in action type make a project greet
00:01:20 – all the code and now we are going to say
00:01:21 – using system and I will say the
00:01:26 – enumeration and so type that en um and
00:01:29 – not tab twice right name is days and now
00:01:34 – T numerate means to list like that so
00:01:39 – the enumerated our case means you will
00:01:41 – type monday tuesday wednesday thursday
00:01:47 – friday saturday and sunday night excuse
00:01:54 – look carefully there is visual c sharp
00:01:57 – come to 35 the name of it then within
00:02:00 – that we have days you see that that's an
00:02:02 – enumeration and it's got its own little
00:02:05 – icon as you can see and then within the
00:02:07 – enumeration we have all of these
00:02:09 – constant
00:02:10 – that we have created named Constance
00:02:12 – prevent Friday Monday Saturday and so on
00:02:14 – so that's the benefit of having the
00:02:16 – navigation bar alright if you click here
00:02:19 – and you know say you chose Wednesday
00:02:20 – then it puts you there you see that you
00:02:23 – can navigate alright that looks like
00:02:26 – this alright that's all we need my
00:02:28 – navigation bar allows you to examine the
00:02:30 – contents of a page all right now another
00:02:34 – big idea is why do we call this a list
00:02:36 – of constants because behind the scenes
00:02:40 – each name it presents a number like that
00:02:46 – that's the reason for calling it named
00:02:47 – constants all right of course it's
00:02:50 – easier to remember Monday Tuesday than
00:02:52 – it is to remember you no one if I say
00:02:53 – one watt or two and you look like what
00:02:56 – to what so monday tuesday now we
00:02:58 – understand right that we use in everyday
00:03:00 – speech okay so here we are going to stay
00:03:03 – here come the following class program
00:03:08 – like that and notice that as soon as you
00:03:11 – type here in the middle box now you've
00:03:13 – got days of an enumeration that's one
00:03:15 – item and now you have program as another
00:03:17 – item see so now we can now recognize the
00:03:20 – types that you are making there you go
00:03:23 – the class program now with in here
00:03:24 – you're going to say for static void main
00:03:27 – entry point into program as usual okay
00:03:31 – so and if we point into program right
00:03:34 – open closed curly braces now you are
00:03:37 – going to get input from user as usual
00:03:39 – input from user otherwise what's the
00:03:41 – point of the program here you will say
00:03:43 – come for that right line and entered day
00:03:47 – of week like that now you will be that n
00:03:51 – so string s equals and here you'll say
00:03:54 – come from that red line through the line
00:03:58 – now once somebody enters the day of the
00:04:01 – weekend for application of errors well
00:04:04 – give the day every week we'll examine
00:04:06 – the possible choices you know we will
00:04:08 – use a switch blocks or switch as we were
00:04:11 – switching on a day of the week right the
00:04:13 – day of the week can assume 17 values and
00:04:16 – we're going to examine each one you're
00:04:18 – going to say the foul it's a case Monday
00:04:20 – and put that within double quotes as a
00:04:22 – string
00:04:23 – then you will perform the following a CW
00:04:25 – and then tab tab and you'll say well say
00:04:28 – the number of days between Monday and
00:04:30 – the day the user has input so Nick first
00:04:32 – case it should be 0 but to make use of
00:04:34 – the enumeration in other words of these
00:04:37 – easy to remember names like Monday
00:04:38 – Tuesday and so on you can type the power
00:04:40 – you okay it type like that and then they
00:04:48 – days and then put a placeholder like
00:04:52 – this and put a period comma and i will
00:04:56 – type int and then you'll say days that
00:05:00 – monday month- int and then days that
00:05:05 – monday closed out the semicolon for this
00:05:08 – step right here this is the most
00:05:09 – important step you put a comment in you
00:05:11 – yeah where it says int days that monday
00:05:15 – that means reach into the enumeration
00:05:18 – grab monday and represented as the
00:05:21 – underlying numerical value okay so this
00:05:25 – means you present monday and the
00:05:30 – underlying numerical values you can
00:05:34 – calculate the end of the case from
00:05:38 – monday all right the rest of this is the
00:05:40 – same thing put a break in here and i
00:05:43 – will say of course case Tuesday and so
00:05:44 – on okay so that case is basically a
00:05:47 – little just copying and pasting the code
00:05:48 – it's the same thing so take this control
00:05:52 – c and then ctrl v down below change this
00:05:55 – to case Tuesday not change where it's
00:05:58 – appropriate to do so over here which is
00:06:00 – case Tuesday here now like that and I'll
00:06:05 – take tell you you know the number of
00:06:06 – days from tuesday to monday right and
00:06:09 – then repeat this again the rest of this
00:06:12 – is automatic and mechanical like that so
00:06:16 – one day and then change that to
00:06:17 – wednesday here too okay i will leave it
00:06:22 – at this point just before the screen
00:06:24 – enough i want you to take this
00:06:25 – application that we are making here and
00:06:27 – now completed by adding the cases for
00:06:30 – the other days of the week if their
00:06:32 – natural extension of what we have done
00:06:33 – here okay
00:06:35 – let me just change the comment so they
00:06:38 – make more sense Mel so here and we go to
00:06:41 – comment right good to keep reviewing the
00:06:43 – basics for this means most means
00:06:45 – represent Tuesday and they're lying
00:06:49 – America value and this here days that
00:06:51 – Wednesday means represent Wednesday as
00:06:56 – the underlying America value because we
00:06:58 – can operate numerically on it there you
00:07:00 – go where then now clearly if you put in
00:07:05 – three and then one for example people
00:07:10 – just like say what does that mean 3-1
00:07:13 – what's the meaning of that when you put
00:07:14 – a once-a-month minus Monday now that I
00:07:16 – understand right that's very obvious the
00:07:18 – meaning of that operation realities
00:07:20 – that's the reason for having me okay
00:07:23 – sounds like this let's give it a go here
00:07:25 – and today a week so I'm to say Tuesday
00:07:35 – and it says one day that's it okay
00:07:37 – nothing to be fond of course is a little
00:07:39 – extension so for example here for
00:07:42 – tuesday probably wonderful one day for
00:07:44 – the other ones days let's do one more so
00:07:46 – debug now and step into there you go go
00:07:53 – to the code here I'll get the day of the
00:07:56 – week right and today a week i'll put in
00:07:59 – wednesday this time i'll let me get a
00:08:01 – little console bundle disappeared for a
00:08:03 – second ago so i will put in wednesday
00:08:06 – like that now that's been read in as you
00:08:11 – can see in a locals window in red there
00:08:14 – you go go back to that case on the
00:08:16 – bottom older than the bottom see that
00:08:18 – you have a mouth of the days of course
00:08:20 – there you go any expand that is going to
00:08:24 – tell you see then there are the name
00:08:25 – Constance all right in a minute that's
00:08:28 – it I perform the calculation break out
00:08:32 – of the program and if you look at the
00:08:34 – output on the window here it says two
00:08:39 – days that's it Kara's closes now vegas i
00:08:45 – want you to minimum your project
00:08:46 – extended application to complete the
00:08:48 – other days monday tuesday
00:08:49 – Wednesday Thursday Friday Saturday and
00:08:50 – Sunday and whatever else he want to
00:08:52 – thank him you know okay maybe because
00:08:55 – I'm you know the difference in terms of
00:08:57 – the number of hours maybe it could be
00:08:58 – with that way what kinds of things can
00:09:00 – be done


Video Url:
http://youtu.be/rQxSUXdxT28

Comments

comments