Pastebins are at the bottom of the log.
[2009/03/05 13:01] Snowdrop Short: hi Adelle
[2009/03/05 13:01] Adelle Fitzgerald: hiya all
[2009/03/05 13:01] M1sha Dallin: I found teh homework useful
[2009/03/05 13:01] Adelle Fitzgerald: :)
[2009/03/05 13:01] M1sha Dallin: Hi Adelle
[2009/03/05 13:01] Starky Rubble: :)
[2009/03/05 13:01] Adelle Fitzgerald: i struggled soo much witht he
homework
[2009/03/05 13:01] Adelle Fitzgerald: i couldnt do it :(
[2009/03/05 13:01] Snowdrop Short: in the end, there is no substitute
for writing code
[2009/03/05 13:02] Snowdrop Short: it's ok
[2009/03/05 13:02] Starky Rubble: I didn`t quite get to the end but i
broght a pastebook
[2009/03/05 13:02] M1sha Dallin: Maybe now that the basics ahve been
conveyed - introduce a problem that illustrates a feature
[2009/03/05 13:02] Starky Rubble: pastebin lol
[2009/03/05 13:02] Snowdrop Short: we'll take a look at what's been
done, and take it from there
[2009/03/05 13:03] Starky Rubble: you mean what we`ve doneÉ
[2009/03/05 13:03] Starky Rubble: crap there goes my hippo again!
[2009/03/05 13:03] Snowdrop Short: but I agree, that maybe we should
try to work on a different angle
[2009/03/05 13:03] Starky Rubble: I have to relog
[2009/03/05 13:03] Starky Rubble: sorry
[2009/03/05 13:03] Snowdrop Short: yes ... what you have done, sorry
about that
[2009/03/05 13:03] M1sha Dallin: I love th elanguage and the IDE
[2009/03/05 13:03] Snowdrop Short: it's ok
[2009/03/05 13:04] M1sha Dallin: It's great for trying things -
getting them to work - then refining when I've learnt something
[2009/03/05 13:05] Snowdrop Short: that's the one of the things I
love about c#, you can get something usefull without having to spend a
ton of time setting up things
[2009/03/05 13:05] M1sha Dallin: yep
[2009/03/05 13:05] Adelle Fitzgerald: i dont have anything to
pastebin, i tried at it, but i was just writing stuff i didnt really
understand. the most I actually did understand was writing a class
with just variables in it... i tried to make some kind of
relationship, but was just getting errors all the time and got
frustraited with it and binned it
[2009/03/05 13:05] Snowdrop Short: it's ok
[2009/03/05 13:06] Adelle Fitzgerald: its led me to think if i am cut
out for this tbh
[2009/03/05 13:06] M1sha Dallin: I went a bit over the top I'm afraid
[2009/03/05 13:06] Starky Rubble: Ahhh me too
[2009/03/05 13:06] Snowdrop Short: well Adelle, it just tells me that
we need to work a bit more on the stuff we've covered already
[2009/03/05 13:06] M1sha Dallin: It's just practice Adelle
[2009/03/05 13:07] M1sha Dallin: if you can do LSL you can do C#
[2009/03/05 13:07] Adelle Fitzgerald: i got to thinking, and i think
this is too advanced for where I am with C#
[2009/03/05 13:07] Snowdrop Short: maybe it is, so we'll track back
to where you are right now, and then progress from there
[2009/03/05 13:08] Adelle Fitzgerald: if i was working with simple
things, like simple strings and integers, loops and things, then I
might be at a better place to understand it, but things like
relationships are too much for me right now
[2009/03/05 13:08] Snowdrop Short: that's ok, I think we can do that
[2009/03/05 13:08] Adelle Fitzgerald: i havent said anything before
in the hope i would suddenly 'get it' but I havent, and I also dont
want to drag M1sha and Starky down
[2009/03/05 13:09] Starky Rubble: heh don't mind me lol
[2009/03/05 13:09] M1sha Dallin: I'm fine - Tuesday is the complex
class
[2009/03/05 13:09] Snowdrop Short: Adelle, if you want to, I can set
aside some extra time for you
[2009/03/05 13:09] M1sha Dallin: I've been getting to grips with
Syntax on the Thursday
[2009/03/05 13:09] Starky Rubble: I would love to restart so if you
want to i am game
[2009/03/05 13:10] Adelle Fitzgerald: that might be good Snowdrop,
just need to find a time that is convenient for us both :)
[2009/03/05 13:10] Starky Rubble: there are always things I miss or
mis-get lol
[2009/03/05 13:10] Snowdrop Short: Marcus, Blue, M1sha what do you
think?
[2009/03/05 13:10] Adelle Fitzgerald: i think I'm at a level where i
could write a counting loop or something like that, very very basic
stuff
[2009/03/05 13:11] Snowdrop Short: I have been pushing forward pretty
fast
[2009/03/05 13:11] M1sha Dallin: I'm happy with whatever
[2009/03/05 13:11] Starky Rubble: Oh hi Marcus!
[2009/03/05 13:11] Adelle Fitzgerald: hi Marcus :)
[2009/03/05 13:11] M1sha Dallin: Yep but Starky and I have programmed
in RL in other languages
[2009/03/05 13:11] M1sha Dallin: concepts are easier to assimilate
[2009/03/05 13:11] Marcus Llewellyn: Hellos. :) As a new arrival with
a background in programming, I'm simply hoping to pick up gems if
knowldge here and there. I'm content to go with the group.
[2009/03/05 13:11] Starky Rubble: true but I am really struggling
with OOP
[2009/03/05 13:12] Starky Rubble: never done it before lol
[2009/03/05 13:12] Adelle Fitzgerald: hehe its funny... I seem to
ahve a better time with Tuesdays class than this one
[2009/03/05 13:12] Snowdrop Short: OOP does require rethinking quite
a bit
[2009/03/05 13:12] Starky Rubble: and I'm an old dog lol
[2009/03/05 13:12] Adelle Fitzgerald: and especially after the
concept of OOC finally sunk in on Tuesday
[2009/03/05 13:12] M1sha Dallin: yep - I've rethought many times - My
homework settled on version 4 :-)
[2009/03/05 13:12] Adelle Fitzgerald: like I said though, just the
concept
[2009/03/05 13:12] Starky Rubble: OOC?
[2009/03/05 13:13] Adelle Fitzgerald: oops
[2009/03/05 13:13] Adelle Fitzgerald: OOP
[2009/03/05 13:13] Marcus Llewellyn: OO isn't alien to me. I'm simply
not what I would regard as proficient in C#.
[2009/03/05 13:13] Snowdrop Short: maybe the tuesday classes are more
your thing then Marcus
[2009/03/05 13:14] Starky Rubble: but hey everyone is welcome!
[2009/03/05 13:14] Snowdrop Short: ok .. I think we should review the
homework, sometimes you can learn by looking at other peoples code
[2009/03/05 13:14] Marcus Llewellyn smiles. :)
[2009/03/05 13:14] Snowdrop Short: yes, everybody is welcome
[2009/03/05 13:14] Starky Rubble: you wanna go first M1sha?
[2009/03/05 13:14] M1sha Dallin: If you want - but I've got a lot of
code
[2009/03/05 13:14] Starky Rubble: mines pretty short
[2009/03/05 13:14] Snowdrop Short: Adelle, how does an extra hour
before the thursday classes fit with your schedule?
[2009/03/05 13:15] Adelle Fitzgerald: i cant then, i have the wiki
meeting right before this class now
[2009/03/05 13:15] Snowdrop Short: ahh ok
[2009/03/05 13:15] Starky Rubble:
http://www.pastebin.ca/1353729
[2009/03/05 13:16] Starky Rubble: 2 hrs?
[2009/03/05 13:16] Starky Rubble: heh
[2009/03/05 13:16] Snowdrop Short: two hours ?
[2009/03/05 13:16] Snowdrop Short: is that how long it took you?
[2009/03/05 13:16] Starky Rubble: before the tHursday claaa
[2009/03/05 13:17] Starky Rubble: no
[2009/03/05 13:17] Snowdrop Short: maybe ... I think I could do that
[2009/03/05 13:17] Starky Rubble: this was more like 12 hrs lol
[2009/03/05 13:17] Snowdrop Short: it's ok, you're new at the
language, and it takes a lot of experimentation
[2009/03/05 13:17] Starky Rubble: oh yeah....
[2009/03/05 13:18] Snowdrop Short: so the way I read your code .. is
this
[2009/03/05 13:18] Snowdrop Short: everything is taking place in the
Main method
[2009/03/05 13:18] Starky Rubble: right
[2009/03/05 13:18] Starky Rubble: I wanted to get it working by
itself and then bring it oover
[2009/03/05 13:19] Snowdrop Short: you first declare a dictionary,
which will let you lookup a friend object, based on the name of the
friend
[2009/03/05 13:19] Starky Rubble: correct
[2009/03/05 13:19] Snowdrop Short: that's often a good approach
[2009/03/05 13:19] Snowdrop Short: you then create 6 friend objects
[2009/03/05 13:19] Snowdrop Short: and add them to your dictionary
[2009/03/05 13:20] Starky Rubble: the dumb way lol
[2009/03/05 13:20] Starky Rubble: in main
[2009/03/05 13:20] Snowdrop Short: it's ok .. it works
[2009/03/05 13:20] Snowdrop Short: the goal right now is to make
something that works
[2009/03/05 13:20] Starky Rubble: :)
[2009/03/05 13:21] Snowdrop Short: there will always be someone
brighter, who can do the same thing in an amazingly clever way
[2009/03/05 13:21] Snowdrop Short: no matter how bright you are :-)
[2009/03/05 13:21] Snowdrop Short: the first priority is make it work
[2009/03/05 13:21] Snowdrop Short: then make it work the right way or
clever way
[2009/03/05 13:21] Snowdrop Short: but first it must work
[2009/03/05 13:22] Snowdrop Short: a dictionary consists of a
collection of a special kind of object
[2009/03/05 13:22] Snowdrop Short: called a keyvalue pair
[2009/03/05 13:22] Snowdrop Short: and the foreach loop in 113 runs
through that collection
[2009/03/05 13:22] Snowdrop Short: one by one
[2009/03/05 13:23] Marcus Llewellyn: 133 :)
[2009/03/05 13:23] Snowdrop Short: you then print the list one by one
[2009/03/05 13:23] Snowdrop Short: sorry.. yes 133
[2009/03/05 13:24] Snowdrop Short: and print their name, id, and
permissions
[2009/03/05 13:24] Starky Rubble: but the name comes from the Key
side of the Pair
[2009/03/05 13:24] Snowdrop Short: yes, I was just going to comment
on that
[2009/03/05 13:24] Starky Rubble: just for fun
[2009/03/05 13:25] Snowdrop Short: your code would have been easier
to read if you had taken the name from the friend class
[2009/03/05 13:25] Snowdrop Short: because now it says: "fKeyVal.Key"
and I to remind myself that the name was the key
[2009/03/05 13:25] Snowdrop Short: if it has said
[2009/03/05 13:25] Starky Rubble: Sorry - I was trying to make sure I
understood KeyValuePais
[2009/03/05 13:26] Snowdrop Short: fKeyVal.Name
[2009/03/05 13:26] Starky Rubble: right
[2009/03/05 13:26] Snowdrop Short: it's ok, just a tip for making the
code more readable
[2009/03/05 13:26] Snowdrop Short: but the most important thing is
that you learned something
[2009/03/05 13:26] Snowdrop Short: and that it works
[2009/03/05 13:26] Snowdrop Short: in that order :-)
[2009/03/05 13:27] Snowdrop Short: next you experiment a bit with the
dictionary
[2009/03/05 13:27] Snowdrop Short: and remove "Bozo"
[2009/03/05 13:27] Starky Rubble: I gotta say that Dictionaries are
almost magically cool!
[2009/03/05 13:27] Starky Rubble: yes
[2009/03/05 13:27] Starky Rubble: and th4en reshow it
[2009/03/05 13:28] Snowdrop Short: that's one of the great things
about c# and other languages like it, there are so many premade things
you can use
[2009/03/05 13:28] Snowdrop Short: directly out of the box, you don't
have to write a ton of things, over and over again
[2009/03/05 13:28] Starky Rubble: V. cool
[2009/03/05 13:28] Snowdrop Short: yes, and then you do it again
[2009/03/05 13:29] Snowdrop Short: long time ago I mentioned
something called "DRY"
[2009/03/05 13:29] Snowdrop Short: "Don't Repeat Yourself"
[2009/03/05 13:29] Starky Rubble: right
[2009/03/05 13:29] Starky Rubble: thats where I wanted to go
[2009/03/05 13:30] Snowdrop Short: so another way you could have
improved it was to create a method called "PrintFriends"
[2009/03/05 13:30] Snowdrop Short: and then reused that
[2009/03/05 13:30] Starky Rubble: get the methods into a class clled
FreindsList
[2009/03/05 13:30] Starky Rubble: only spelled right
[2009/03/05 13:30] Snowdrop Short: well, you solved the task
[2009/03/05 13:30] Snowdrop Short: and hopefully learned a bit of c#
syntax along the way
[2009/03/05 13:31] Starky Rubble: I was unable to get the Dictionary
out of main
[2009/03/05 13:31] Snowdrop Short: even discovered the Dictionary
class
[2009/03/05 13:31] Starky Rubble: Main
[2009/03/05 13:31] Snowdrop Short: ok ... it looks good
[2009/03/05 13:31] Snowdrop Short: M1sha .. are you up for it as
well?
[2009/03/05 13:32] M1sha Dallin: yep
[2009/03/05 13:32] M1sha Dallin: I took a slightly different approach
- similar but different
[2009/03/05 13:32] M1sha Dallin: I created classes for Person and a
PersonDatabase
[2009/03/05 13:32] Starky Rubble: heh
[2009/03/05 13:32] Snowdrop Short: no two people ever does everything
the same way
[2009/03/05 13:33] M1sha Dallin: then a class for Friend which
referenced two persons
[2009/03/05 13:33] Snowdrop Short: ok .. sounds interesting
[2009/03/05 13:33] M1sha Dallin: and a friend database
[2009/03/05 13:33] Snowdrop Short: how did you make the database?
[2009/03/05 13:33] M1sha Dallin: I used a keyed collection to avoid
duplicating the key in the value
[2009/03/05 13:33] M1sha Dallin: The keyed collection for reference
is in
http://www.pastebin.ca/1353722
[2009/03/05 13:34] M1sha Dallin: but the real code is in
http://www.pastebin.ca/1353767
[2009/03/05 13:34] M1sha Dallin: I added an event to handle deletion
of a person and propagation to the friends database
[2009/03/05 13:36] M1sha Dallin: It'sgone quiet
[2009/03/05 13:36] Snowdrop Short: reading the code.. mouth agape
[2009/03/05 13:36] Marcus Llewellyn: I've been waiting for pastebin
to respond. :P
[2009/03/05 13:37] Starky Rubble: whoa - jusrt on the delegates code
[2009/03/05 13:37] M1sha Dallin: that was the bit I had most trouble
with :-)
[2009/03/05 13:39] Starky Rubble: I like how you labeled the Person
object components
[2009/03/05 13:39] Starky Rubble: it makes the ro;es very clear
[2009/03/05 13:39] Starky Rubble: roles
[2009/03/05 13:40] M1sha Dallin: naming is the hardest part I think
[2009/03/05 13:40] M1sha Dallin: and of methods - if you want the
code to read like english
[2009/03/05 13:41] M1sha Dallin: not sure I managed - kept changing
my mind between class methods and object methods
[2009/03/05 13:41] Snowdrop Short: ok ...
[2009/03/05 13:41] Snowdrop Short: nothing much I can say
[2009/03/05 13:42] M1sha Dallin: that good?
[2009/03/05 13:42] M1sha Dallin: or that bad?
[2009/03/05 13:42] Snowdrop Short: besides.. you have really gone a
lot further than I imagined
[2009/03/05 13:42] Snowdrop Short: it is quite good
[2009/03/05 13:42] M1sha Dallin: yep - got carried away
[2009/03/05 13:42] Marcus Llewellyn: I mean zero insult... but
there's a programming axion. K.I.S.S. :)
[2009/03/05 13:43] Starky Rubble: thats a lotta code!
[2009/03/05 13:43] M1sha Dallin: it was the minimum to do what I
wanted it to do :-)
[2009/03/05 13:43] Marcus Llewellyn nods. amiably. :)
[2009/03/05 13:43] Starky Rubble: and it works
[2009/03/05 13:43] M1sha Dallin: yep
[2009/03/05 13:44] Snowdrop Short: yes
[2009/03/05 13:44] Snowdrop Short: I haven't run it, but it
definately looks as if it should work
[2009/03/05 13:44] M1sha Dallin: Wasn't sure if it would compile
under Mono
[2009/03/05 13:44] Snowdrop Short: one tiny nit picking thing
[2009/03/05 13:44] Snowdrop Short: but really it is minor
[2009/03/05 13:45] Snowdrop Short: sometimes you use capitalized
parameters e.g. in line 375
[2009/03/05 13:45] Snowdrop Short: "Person"
[2009/03/05 13:45] M1sha Dallin: yep - what is the convention?
[2009/03/05 13:46] Snowdrop Short: and in line 39 of your specialized
collection
[2009/03/05 13:46] Snowdrop Short: you use "item"
[2009/03/05 13:46] Snowdrop Short: the conventions for paramters
differ, but most of the time it is called camel case for parameters
[2009/03/05 13:46] Snowdrop Short: e.g.
[2009/03/05 13:46] Snowdrop Short: bigBadAndUgly
[2009/03/05 13:47] M1sha Dallin: ok - first is lc
[2009/03/05 13:47] Snowdrop Short: each word starts with a capital
letter, except the first word
[2009/03/05 13:47] M1sha Dallin: I'll do some tweaking
[2009/03/05 13:47] Starky Rubble: is there a 'style sheet' somewhere?
[2009/03/05 13:48] M1sha Dallin: I wasn't sure of convention for
{ and } either - left the IDE to place them
[2009/03/05 13:48] Snowdrop Short:
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=336
[2009/03/05 13:49] Starky Rubble: noted... thaks
[2009/03/05 13:49] M1sha Dallin: ty
[2009/03/05 13:49] Starky Rubble: so Snowdrop do you have a version
of Friends?
[2009/03/05 13:49] Snowdrop Short: actually I don't
[2009/03/05 13:50] Snowdrop Short: I thought about it
[2009/03/05 13:50] Snowdrop Short: but based on some input I received
[2009/03/05 13:50] Snowdrop Short: I decided against it
[2009/03/05 13:50] Starky Rubble: okie doke
[2009/03/05 13:50] Snowdrop Short: I would be too focussed on the
object orienting
[2009/03/05 13:50] Snowdrop Short: and less on the syntax and coding
[2009/03/05 13:51] Snowdrop Short: so I thought that maybe we should
put our little friends class excersise on the shelf for a little while
[2009/03/05 13:51] Starky Rubble: ok
[2009/03/05 13:51] Snowdrop Short: and work on syntax
[2009/03/05 13:52] Snowdrop Short: and then work from that angle
[2009/03/05 13:52] Starky Rubble: sure
[2009/03/05 13:52] Snowdrop Short: slowly extrapolating from that
[2009/03/05 13:53] M1sha Dallin: ok
[2009/03/05 13:53] Snowdrop Short: I was thinking about making a
small calculator
[2009/03/05 13:54] M1sha Dallin: gui application?
[2009/03/05 13:54] Starky Rubble: (reverse polish notation comes back
to mind)
[2009/03/05 13:54] M1sha Dallin: :-)
[2009/03/05 13:54] Snowdrop Short: let's start simple
[2009/03/05 13:55] Snowdrop Short: besides gui's are going to cause
problems
[2009/03/05 13:55] Snowdrop Short: unless we're all using the same
operating system
[2009/03/05 13:55] M1sha Dallin: yep - why I asked
[2009/03/05 13:55] Starky Rubble: do it on a prim lol
[2009/03/05 13:56] Snowdrop Short: so the first task would be to
create a small program
[2009/03/05 13:56] Snowdrop Short: which read two numbers off the
keyboard on a console window
[2009/03/05 13:56] Starky Rubble: ok
[2009/03/05 13:56] Snowdrop Short: and simply printed the sum of two
numbers
[2009/03/05 13:57] Snowdrop Short: so lets dig out our IDE's and
create a new console project
[2009/03/05 13:58] Snowdrop Short: called "Calculator"
[2009/03/05 13:58] Adelle Fitzgerald: kk
[2009/03/05 13:59] Starky Rubble: we can drop the Linq collection?
[2009/03/05 13:59] Snowdrop Short: yes
[2009/03/05 13:59] Starky Rubble: text too?
[2009/03/05 13:59] Snowdrop Short: you'll only need "System"
[2009/03/05 14:00] Starky Rubble: and rename Program to Main?
[2009/03/05 14:00] Starky Rubble: Mainclass
[2009/03/05 14:01] Snowdrop Short: if you want to.. that's mainly
because I used Mono Develop
[2009/03/05 14:01] Starky Rubble: right
[2009/03/05 14:01] Starky Rubble: ok
[2009/03/05 14:04] Starky Rubble: PASTEBINNING?
[2009/03/05 14:04] Starky Rubble: oops caps lol
[2009/03/05 14:04] Snowdrop Short nods
[2009/03/05 14:04] Snowdrop Short: ok
[2009/03/05 14:06] Snowdrop Short:
http://www.pastebin.ca/1353866
[2009/03/05 14:07] Snowdrop Short: do you have it?
[2009/03/05 14:07] Marcus Llewellyn: Are we suppose to put a link to
our efforts?
[2009/03/05 14:07] Adelle Fitzgerald: i got it
[2009/03/05 14:08] Snowdrop Short nods .. that would be nice
[2009/03/05 14:08] Marcus Llewellyn:
http://www.pastebin.ca/1353867
[2009/03/05 14:08] Starky Rubble: heh thhat was quick
[2009/03/05 14:09] Marcus Llewellyn: :)
[2009/03/05 14:10] Starky Rubble: ok
[2009/03/05 14:11] Starky Rubble: you guys used different methods for
turning the dtring input into a number
[2009/03/05 14:11] Snowdrop Short: yes
[2009/03/05 14:11] Starky Rubble: Parse must be part of int?
[2009/03/05 14:11] Snowdrop Short: both works fine :-)
[2009/03/05 14:11] Snowdrop Short: it is a static method on int
[2009/03/05 14:11] Marcus Llewellyn: But Snowdrops is less verbose. I
will try to remember it.
[2009/03/05 14:12] Snowdrop Short: well, I don't even have prompts
[2009/03/05 14:12] Starky Rubble: true
[2009/03/05 14:13] Snowdrop Short: the Convert class is rarely used
[2009/03/05 14:13] Marcus Llewellyn: No need if the datatypes have
methods of their own. I should have thought of that. :P
[2009/03/05 14:14] M1sha Dallin: I like the Int.Parse
[2009/03/05 14:14] M1sha Dallin: I was writing a check method
[2009/03/05 14:14] Snowdrop Short: and both of our programs have the
same vulnerabilities
[2009/03/05 14:14] Snowdrop Short: if it isn't an integer .. it
crashes with an exception
[2009/03/05 14:15] M1sha Dallin:
http://www.pastebin.ca/1353874
[2009/03/05 14:15] Snowdrop Short nods
[2009/03/05 14:15] Snowdrop Short: that will do it
[2009/03/05 14:16] Snowdrop Short: so .. let me try to show you
another way
[2009/03/05 14:18] Snowdrop Short:
http://www.pastebin.ca/1353880
[2009/03/05 14:19] Snowdrop Short: see the difference?
[2009/03/05 14:19] M1sha Dallin: :-) need to know al the inbuilt
methods
[2009/03/05 14:19] Marcus Llewellyn: Ah yeah... makes sense.
[2009/03/05 14:20] Snowdrop Short: that's part of learning the
language
[2009/03/05 14:20] Marcus Llewellyn: I don't know the out keyword.
Could you define it for me quick?
[2009/03/05 14:20] Snowdrop Short: to learn the inbuild things
[2009/03/05 14:20] Snowdrop Short: and c# has a lot of those
[2009/03/05 14:21] Snowdrop Short: out shows you that the method will
output a value in that parameter, but never read any values from it
[2009/03/05 14:21] Marcus Llewellyn: Ah, gotcha. :)
[2009/03/05 14:22] Snowdrop Short: any parameter cannot be changed
[2009/03/05 14:22] Snowdrop Short: meaning that it cannot have "side
effects"
[2009/03/05 14:22] Snowdrop Short: unless you specifically declare it
to do so
[2009/03/05 14:22] Snowdrop Short: either by using "ref" or "out"
[2009/03/05 14:22] Snowdrop Short: "out" means "output only"
[2009/03/05 14:23] Snowdrop Short: "ref" means "read and write"
[2009/03/05 14:23] Marcus Llewellyn: So out is a one-way reference?
[2009/03/05 14:23] Snowdrop Short: yes, a oneway output
[2009/03/05 14:23] Marcus Llewellyn: Thanks. :)
[2009/03/05 14:23] Snowdrop Short: and the default is a oneway input
[2009/03/05 14:23] Marcus Llewellyn nods amiably.
[2009/03/05 14:23] Marcus Llewellyn: Got it.
[2009/03/05 14:24] Starky Rubble: ok
[2009/03/05 14:24] Snowdrop Short: so the onlyway "TryParse" can
return a boolean indicating success or failure, is by having an "out"
parameter for the actual result
[2009/03/05 14:25] M1sha Dallin: the out is for the integer?
[2009/03/05 14:25] M1sha Dallin: the function value is the boolean -
I think
[2009/03/05 14:25] Snowdrop Short: yes
[2009/03/05 14:25] Starky Rubble: right
[2009/03/05 14:26] Snowdrop Short: true for success, false for
failure to convert the string to an integer
[2009/03/05 14:26] Starky Rubble: the out parameter is the integer if
there is success
[2009/03/05 14:26] M1sha Dallin: ok
[2009/03/05 14:26] Snowdrop Short: not ... I haven't told you the
full story about "ref" and "out"
[2009/03/05 14:26] Snowdrop Short: but I don't want to confuse things
too much
[2009/03/05 14:26] Marcus Llewellyn: If it had failed, a or b would
remain uninitialized?
[2009/03/05 14:27] Snowdrop Short: yes
[2009/03/05 14:27] Starky Rubble: you concatenated the string
declaration of the inputs with the actual input method too/
[2009/03/05 14:27] Snowdrop Short: but there is no such thing as an
uninitialized value in c#
[2009/03/05 14:27] Marcus Llewellyn: Ah, okay
[2009/03/05 14:27] Snowdrop Short: they are always initialized to a
default value
[2009/03/05 14:27] Snowdrop Short: 0 for numbers
[2009/03/05 14:28] Snowdrop Short: "null" for complex things
[2009/03/05 14:28] Snowdrop Short: like arrays, class handles etc
[2009/03/05 14:28] Snowdrop Short: object handles ... sorry
[2009/03/05 14:28] Starky Rubble: and strings
[2009/03/05 14:28] Snowdrop Short: yes, strings are complex types as
well
[2009/03/05 14:28] Marcus Llewellyn: An empty string could be tested
with two quotes? Eg: ""
[2009/03/05 14:29] Snowdrop Short: there is a difference between
empty and null
[2009/03/05 14:29] Starky Rubble: oh
[2009/03/05 14:29] Snowdrop Short: null means value unknown
[2009/03/05 14:30] Snowdrop Short: but emptystring "" or
"string.Empty" actually means the value is known, but empty
[2009/03/05 14:30] Marcus Llewellyn: Ah, good to know.
[2009/03/05 14:30] Starky Rubble: right
[2009/03/05 14:30] Snowdrop Short: e.g. lets say you are measuring ph
values of a fluid
[2009/03/05 14:30] Snowdrop Short: the 0 is a valid value
[2009/03/05 14:30] Snowdrop Short: how do you know if it has been
measured or not?
[2009/03/05 14:31] Snowdrop Short: or age in years
[2009/03/05 14:31] Snowdrop Short: what about a new born
[2009/03/05 14:31] Starky Rubble: if PH != null;
[2009/03/05 14:31] Snowdrop Short: ?
[2009/03/05 14:31] Snowdrop Short: if it was a string
[2009/03/05 14:31] Starky Rubble: right
[2009/03/05 14:31] Snowdrop Short: actually you can even declare that
null should be a valid value for an integer
[2009/03/05 14:32] Starky Rubble: now now now hehe
[2009/03/05 14:32] Snowdrop Short: let me show you
[2009/03/05 14:32] Marcus Llewellyn: I see. In this case, null
indicated the absence of any information, differentiated from a simple
zero or empty.
[2009/03/05 14:32] Starky Rubble: heh
[2009/03/05 14:33] Snowdrop Short: yes
[2009/03/05 14:33] Snowdrop Short: that's usually what null really
means "absence of data"
[2009/03/05 14:33] Snowdrop Short: you could write int?
[2009/03/05 14:34] Snowdrop Short: that would declare a special type
of integer, which could have the value "null"
[2009/03/05 14:34] Snowdrop Short: c# has some pretty fancy things
actually :-)
[2009/03/05 14:35] Marcus Llewellyn: That would sort of "clear" the
null of any value?
[2009/03/05 14:35] Snowdrop Short: yes
[2009/03/05 14:35] Starky Rubble: but Tryparse works great for our
current need.
[2009/03/05 14:35] Starky Rubble: TryParse
[2009/03/05 14:35] Snowdrop Short: it does
[2009/03/05 14:36] Snowdrop Short: the same thing can be used on
float and other types
[2009/03/05 14:36] Starky Rubble: right
[2009/03/05 14:36] Snowdrop Short: but lets look at another oddity
[2009/03/05 14:37] Snowdrop Short: my code simply uses "a+b"
[2009/03/05 14:37] Starky Rubble: yes
[2009/03/05 14:37] Snowdrop Short: and Marcus' code uses a
converttostring
[2009/03/05 14:38] Marcus Llewellyn: I was wondering... I see you
didn't convert. I was trying to be safe.
[2009/03/05 14:38] Starky Rubble: theres ToString too... I believe
[2009/03/05 14:38] Snowdrop Short: everything in c# has some basic
methods available on them
[2009/03/05 14:38] Snowdrop Short: "CompareTo"
[2009/03/05 14:38] Snowdrop Short: Equals
[2009/03/05 14:39] Snowdrop Short: GetHashCode
[2009/03/05 14:39] Snowdrop Short: GetType
[2009/03/05 14:39] Starky Rubble: everything?
[2009/03/05 14:39] Snowdrop Short: ToString
[2009/03/05 14:39] Snowdrop Short: everything
[2009/03/05 14:40] Starky Rubble: so these are methods on the Object
class?
[2009/03/05 14:40] Snowdrop Short: yes
[2009/03/05 14:40] Marcus Llewellyn: Oh... I could actually even have
done: (i + j).ToString
[2009/03/05 14:40] Starky Rubble: see? I did learn sumthing
[2009/03/05 14:40] Snowdrop Short: and since everything has a
ToString method
[2009/03/05 14:40] Marcus Llewellyn: That's neat
[2009/03/05 14:40] Snowdrop Short: the framework knows that it must
output strings on the console
[2009/03/05 14:41] Snowdrop Short: and that everything has a ToString
methodh
[2009/03/05 14:41] Snowdrop Short: and since a+b is an int
[2009/03/05 14:41] Snowdrop Short: it automatically calls "ToString"
on that new temporary integer
[2009/03/05 14:42] Starky Rubble: so the guy behind the curtain makes
it so when you say a+b... nice!
[2009/03/05 14:42] Snowdrop Short: yes
[2009/03/05 14:42] Snowdrop Short: automagically :-)
[2009/03/05 14:43] Starky Rubble: we're not in kansasToto... lol
[2009/03/05 14:43] Marcus Llewellyn: Hehe
[2009/03/05 14:43] Snowdrop Short: c# is a relatively modern
programming language
[2009/03/05 14:44] Snowdrop Short: things like that makes it easy and
quick to write some useable things in c#
[2009/03/05 14:44] Starky Rubble: Ok
[2009/03/05 14:45] Starky Rubble: So if we took the 'summing' and
made it a method that takes two numbers would that be 'Encapsulating'?
[2009/03/05 14:46] Snowdrop Short: in a way
[2009/03/05 14:46] Snowdrop Short: Encapsulating also implies
"hiding"
[2009/03/05 14:46] Starky Rubble: encapsulating is a vague concept
for me
[2009/03/05 14:46] Snowdrop Short: meaning that you don't care about
how it is implemented
[2009/03/05 14:46] Snowdrop Short: you just knows what it does
[2009/03/05 14:47] Snowdrop Short: in broad terms
[2009/03/05 14:47] Starky Rubble: once it works thats true hehe
[2009/03/05 14:47] Snowdrop Short: and you have no access to the
internals
[2009/03/05 14:47] Snowdrop Short: e.g. the dictionary class
[2009/03/05 14:47] Starky Rubble: a black box
[2009/03/05 14:47] Marcus Llewellyn: Like a wrapper.
[2009/03/05 14:47] Snowdrop Short: or collection
[2009/03/05 14:47] Snowdrop Short: black box is a good name
[2009/03/05 14:48] Snowdrop Short: do you know how a dictionary is
implemented?
[2009/03/05 14:48] Starky Rubble: I peeked
[2009/03/05 14:48] Marcus Llewellyn: A linked list?
[2009/03/05 14:48] Marcus Llewellyn: Dunno. lol
[2009/03/05 14:48] Starky Rubble: hash table
[2009/03/05 14:48] M1sha Dallin: It has a hash function
[2009/03/05 14:48] Starky Rubble: self resizing
[2009/03/05 14:48] Starky Rubble: quite astonishing really
[2009/03/05 14:49] Snowdrop Short: but if I changed it to a binary
search tree
[2009/03/05 14:49] Snowdrop Short: it would still work
[2009/03/05 14:49] Starky Rubble: (he said remembering the code it
took to write that kindo thing in a low level language)
[2009/03/05 14:49] Snowdrop Short: because you cannot access the
internals
[2009/03/05 14:50] Snowdrop Short: that's actually what encapsulation
is about
[2009/03/05 14:50] Starky Rubble: Ok... thats what I had in mind
[2009/03/05 14:50] M1sha Dallin: The similarities were useful - I
started using a dictionary - it was trivial to change to an indexed
collection
[2009/03/05 14:50] Marcus Llewellyn: Is the Dictionary inheritable?
[2009/03/05 14:51] Snowdrop Short: almost everything in c# is
inhertable
[2009/03/05 14:51] Snowdrop Short: you can delclare that it is "non-
inhertiable", but it isn't used much
[2009/03/05 14:51] Snowdrop Short: only in special situations
[2009/03/05 14:52] Starky Rubble: so if we encapsulated (for lack of
a better verb) the summing function, we could do the same for the
other needed functions
[2009/03/05 14:52] M1sha Dallin: single instance data?
[2009/03/05 14:52] Snowdrop Short: single instance data? whats that?
[2009/03/05 14:52] Starky Rubble: to build our calculator
[2009/03/05 14:52] Snowdrop Short: yes
[2009/03/05 14:53] Snowdrop Short: acutally the next step should be
to add a choice between addition and subtraction
[2009/03/05 14:53] M1sha Dallin: Single Instance => An OO form of
global data
[2009/03/05 14:53] Snowdrop Short: singletons
[2009/03/05 14:54] Snowdrop Short: the "final" keyword is mostly used
when you write c# code that accesses the hardware
[2009/03/05 14:54] Marcus Llewellyn: A Main class might be a
singleton, yes? A static class?
[2009/03/05 14:54] Snowdrop Short: or use special data, which the
garbage collector cannot know about
[2009/03/05 14:55] Marcus Llewellyn: Er, static object
[2009/03/05 14:55] Snowdrop Short: yes, a main class may be a
singleton
[2009/03/05 14:55] Starky Rubble: we're way off topic here lol
[2009/03/05 14:55] Marcus Llewellyn: lol
[2009/03/05 14:55] Snowdrop Short: yes .. a bit
[2009/03/05 14:55] Snowdrop Short: that's more like tuedays talk
[2009/03/05 14:56] Snowdrop Short: I'd suggest that we change the
program
[2009/03/05 14:56] Snowdrop Short: to read 3 line of input
[2009/03/05 14:56] Snowdrop Short: a number
[2009/03/05 14:56] Snowdrop Short: and operator , either '+' or '-'
[2009/03/05 14:56] Snowdrop Short: and then the second number
[2009/03/05 14:56] Snowdrop Short: and finally prints the result
[2009/03/05 14:57] Starky Rubble: ok
[2009/03/05 14:57] Snowdrop Short: lets have that as the homework for
next thursday
[2009/03/05 14:57] Snowdrop Short: don't go overboard
[2009/03/05 14:57] M1sha Dallin: ok
[2009/03/05 14:57] Starky Rubble: o
[2009/03/05 14:57] Starky Rubble: ok
[2009/03/05 14:57] M1sha Dallin: :-)
[2009/03/05 14:57] Snowdrop Short: keep it simple :-)
[2009/03/05 14:58] Starky Rubble: Adelle do you have a complete log -
I dont
[2009/03/05 14:58] Adelle Fitzgerald: i do yes :)
[2009/03/05 14:58] Starky Rubble: cool
[2009/03/05 14:58] Snowdrop Short: I think it is time to round this
up for today
[2009/03/05 14:58] Starky Rubble: yes
[2009/03/05 14:58] M1sha Dallin: yep - bedtime
[2009/03/05 14:58] Marcus Llewellyn smiles. :)
[2009/03/05 14:58] M1sha Dallin: ty Snowdrop
[2009/03/05 14:58] Starky Rubble: indeed thanks!
[2009/03/05 14:58] Snowdrop Short: Adelle .. how does an hour before
the wiki hour fit you?
[2009/03/05 14:59] Marcus Llewellyn smiles. :)
[2009/03/05 14:59] Adelle Fitzgerald: it will be tight, but I think I
can do that
[2009/03/05 14:59] Snowdrop Short: well, you could give me a few
suggestions for other times
[2009/03/05 14:59] Adelle Fitzgerald nods
[2009/03/05 14:59] Adelle Fitzgerald: ill have a think, and give you
a shout on IRC
[2009/03/05 15:00] Snowdrop Short: ok .. great
[2009/03/05 15:00] Snowdrop Short: well it's bed time for me
[2009/03/05 15:00] Snowdrop Short: it's midnigh here
[2009/03/05 15:00] Adelle Fitzgerald: okies
[2009/03/05 15:00] Starky Rubble: gnight
[2009/03/05 15:00] Adelle Fitzgerald: thanks Snowdrop :)
[2009/03/05 15:00] Snowdrop Short: nite
[2009/03/05 15:00] M1sha Dallin: g'night
[2009/03/05 15:00] Adelle Fitzgerald: sleep well
[2009/03/05 15:00] M1sha Dallin: and for me - g'night all
http://www.pastebin.ca/1353729
Adding Friends to our persons
I got pretty confused trying to do this so i am going to write it out
since Snowdrop said that if you write it out, often the nouns are the
needed objects/classes and the verbs are the methods.
So we need to add a way for a person to have many friends.
That seems to suggest we need a class of Friend objects.
We will need to know each Friend's name, how to reach them (in the
grid that means their UUID) and maybe some other stuff.
I am going to say we need to know what kind of benefits (perms) they
have (e.g. would you lend them money?)
So a Friend has a name, id, and perms.
Also we will need to add and dump friends easily, change their perms
(U R my new BFF!), and display them all,
That seems to suggest we will need four methods but wait... add to
what? We need a container for many Friend objects.
Snowdrop said we should decide which of the several collections is
appropriate.
She had previously said that ArrayLists are not used all that often.
I figgered I'd look at List and Dictionary.
Lists are really a lot like Arrays. If we used a list we'd have to
look at every entry to see if it matched before ading a new friend or
getting their ID.
Dictionaries OTOH, are made for this job. They are a hashed table so
loookups are fast and easy.
They also come with Add and Remove methods and have a ContainsKey
method for looking up.
Dictionaries have a pair of components... the Key and the Value.
The Key is the index and since I would be using it I wanted the index
to be what I woulld look up... their name.
The Value is the Friend object from above so the KeyValue pair is
(Friend.Name, Friend)
To display all your friends you loop through the dictionary using
ForEach and KeyValuePair
I want to move the dictionary out of Main and into a class called
FriendsList and then move the Friends and FriendsList classes into
Person since a Person would have a FreindsList (empty or not) as well
as a Spouse.
I have been unable to do that so far.
Here is my working Friends dictionary code:
using System;
using System.Collections;
using System.Collections.Generic;
namespace FriendsHW
{
// Constants that will be known program wide - each power of two
is one bit and indicates a permission level
// TBD BUDDY should be either be assigned for all new Friends or
dropped?
static class PermFlags
{
public const int BUDDY = 1;
public const int LOVER = 2;
public const int EX = 4;
public const int WORK = 8;
public const int CLASS = 16;
public const int MONEY = 32;
}
//Friends have an ID, a name, and maybe some benefits
(permissions)
//Friend will be the value part of a Dictonary
//TBD the ID data should be capable of holdng a UUID
public class Friend
{
public Friend(string name, int id, int perms)
{
Name = name;
ID = id;
Perms = perms;
}
//these are private to this class
private string f_name;
private int f_id;
private int f_perms;
//Methods for getting or setting Friend values
public string Name
{
get { return f_name; }
set { f_name = value; }
}
public int ID
{
get { return f_id; }
set { f_id = value; }
}
public int Perms
{
get { return f_perms; }
set { f_perms = value; }
}
}
class MainClass
{
static void Main(string[] args)
{
//Create a collection (Dictionary) of Friends - TBD the
key should be a Guid
Dictionary<string, Friend> Friends = new
Dictionary<string, Friend>();
//hard code some friends - ID, Name, Perms (using the
PermsFlags Constants)
Friend f1 = new Friend("Mywife", 11, PermFlags.BUDDY |
PermFlags.LOVER | PermFlags.MONEY);
Friend f2 = new Friend("Snowdrop", 13, PermFlags.BUDDY |
PermFlags.WORK);
Friend f3 = new Friend("Bozo", 17, PermFlags.BUDDY |
PermFlags.EX);
Friend f4 = new Friend("Adelle", 19, PermFlags.BUDDY |
PermFlags.CLASS);
Friend f5 = new Friend("M1sha", 23, PermFlags.BUDDY |
PermFlags.CLASS);
Friend f6 = new Friend("Bluewall", 29, PermFlags.BUDDY |
PermFlags.CLASS);
Friends.Add(f1.Name, f1);
Friends.Add(f2.Name, f2);
Friends.Add(f3.Name, f3);
Friends.Add(f4.Name, f4);
Friends.Add(f5.Name, f5);
Friends.Add(f6.Name, f6);
//Ok now lets show the Dictionary Key, followed by 2 of
the 3 Friend Values
foreach (KeyValuePair<string, Friend> fKeyVal in Friends)
{
Console.WriteLine(
"Friend Key: {0}, ID: {1} Permissions: {2}",
fKeyVal.Key,
fKeyVal.Value.ID,
fKeyVal.Value.Perms);
//if ((fKeyVal.Value.Perms & PermFlags.LOVER) =
PermFlags.LOVER)
//{
// Console.WriteLine("Mon Cherie");
//}
//Console.WriteLine( Convert.ToString
(fKeyVal.Value.Perms & PermFlags.LOVER));
}
//Drop a couple of lines down the screen
Console.WriteLine("\n\n");
//Lets remove the stinky Bozo from our Friends list
// Remove an item with a specific key
if (Friends.ContainsKey("Bozo"))
Friends.Remove("Bozo");
//Ok now lets show the new Dictionary as before
foreach (KeyValuePair<string, Friend> fKeyVal in Friends)
{
Console.WriteLine(
"Friend Key: {0}, ID: {1} Permissions: {2}",
fKeyVal.Key,
fKeyVal.Value.ID,
fKeyVal.Value.Perms);
}
}
}
}
http://www.pastebin.ca/1353722
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace MyCollections
{
// A class that works just like KeyedCollection, but sends event
// notifications whenever the collection has a remove event
public class KeyedCollectionWithRemoveEvent<TKey, TItem> :
KeyedCollection<TKey, TItem>
{
// A delegate type for hooking up remove notifications.
public delegate void RemovedEventHandler(object sender,
ItemInfoEventArgs e);
public class ItemInfoEventArgs : EventArgs
{
public ItemInfoEventArgs(TItem item)
{
this._Item = item;
}
public readonly TItem _Item;
}
// An event that clients can use to be notified whenever an
// elements of the collection is removed
public event RemovedEventHandler Removed;
// Invoke the OnRemoved event; called whenever item removed
protected virtual void OnRemoved(ItemInfoEventArgs e)
{
if (Removed != null)
Removed(this, e);
}
// Override the Remove method
// invoke event after
public new Boolean Remove(TItem item)
{
ItemInfoEventArgs ItemInformation = new ItemInfoEventArgs
(item);
OnRemoved(ItemInformation);
Boolean b = base.Remove(item);
return b;
}
protected override TKey GetKeyForItem(TItem item)
{
throw new NotImplementedException();
}
}
}
http://www.pastebin.ca/1353767
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using MyCollections;
namespace FriendsHomework
{
//
-----------------------------------------------------------------------
class PersonCollection : KeyedCollectionWithRemoveEvent<Guid,
Person>
{
protected override Guid GetKeyForItem(Person Person)
{
return Person.PersonGuid;
}
}
//
-----------------------------------------------------------------------
class EventListener
{
private PersonCollection Database;
public EventListener(PersonCollection PersonDatabase)
{
Database = PersonDatabase;
Database.Removed += new
PersonCollection.RemovedEventHandler(Removed);
}
// This will be called whenever the list changes.
private void Removed(object sender,
PersonCollection.ItemInfoEventArgs e)
{
FriendDatabase.DeleteFriendship(e._Item);
}
public void Detach()
{
// Detach the event
Database.Removed -= new
PersonCollection.RemovedEventHandler(Removed);
}
}
//
-----------------------------------------------------------------------
public class Person
{
public Person(string name)
{
_Name = name;
_BirthDate = DateTime.UtcNow;
_PersonGuid = Guid.NewGuid();
}
// Properties for the Person object
private Guid _PersonGuid;
private string _Name;
private DateTime _BirthDate;
// Accessor functions
public Guid PersonGuid
{
get
{
return this._PersonGuid;
}
set
{
this._PersonGuid = PersonGuid;
}
}
public string Name
{
get
{
return this._Name;
}
set
{
this._Name = Name;
}
}
public DateTime BirthDate
{
get
{
return this._BirthDate;
}
set
{
this._BirthDate = BirthDate;
}
}
// Instance Methods
// Method: to write details of a Person to the Console
// Parameters: Person
// Return: None
//
public void WritePersonToConsole()
{
Console.Write(this.Name);
}
}
//
-----------------------------------------------------------------------
public class Friend
{
public Friend(Person person, Person friend)
{
_Person1 = person;
_Person2 = friend;
_BecameFriendsOn = DateTime.UtcNow;
}
// Properties for the Friends object
private Person _Person1;
private Person _Person2;
private DateTime _BecameFriendsOn;
// Accessor functions
public Person Person1
{
get
{
return this._Person1;
}
set
{
this._Person1 = Person1;
}
}
public Person Person2
{
get
{
return this._Person2;
}
set
{
this._Person2 = Person2;
}
}
public DateTime BecameFriendsOn
{
get
{
return this._BecameFriendsOn;
}
set
{
this._BecameFriendsOn = BecameFriendsOn;
}
}
// Instance Methods
// Method: to write details of a Friendship to the Console
// Parameters: Person
// Return: None
//
public void WriteFriendshipToConsole()
{
this.Person1.WritePersonToConsole();
Console.Write(" is friends with ");
this.Person2.WritePersonToConsole();
Console.WriteLine();
}
}
//
-----------------------------------------------------------------------
public class FriendDatabase
{
static List<Friend> _FriendList = new List<Friend>();
//TODO - Locking - is this thread safe?
// Public Methods
// Method: to return the Friends object for two persons
// Parameters: in Person
// in Person
// Return: Friends (or null if friends relationship does
not exist)
//
public Friend GetFriendship(Person P1, Person P2)
{
foreach (Friend F in _FriendList)
{
if ((P1 == F.Person1 && P2 == F.Person2) ||
(P1 == F.Person2 && P2 == F.Person1)) return F;
}
return null;
}
// Method: to create and record (in the database) a friendship
// Parameters: in Person
// in Person
// Return: Friends
//
public Friend MakeFriendship(Person P1, Person P2)
{
Friend NowFriends = new Friend(P1, P2);
if (NowFriends != null) _FriendList.Add(NowFriends);
return NowFriends;
}
// Method: to delete and remove (from the database) a
friendship
// Parameters: in Friends
// Return: true if friendship deleted
// false if friendship was not present
//
public Boolean DeleteFriendship(Friend R)
{
if (!_FriendList.Contains(R)) return false;
_FriendList.Remove(R);
return true;
}
// Method: to delete and remove (from the database) a
friendship
// Parameters: in Person
// in Person
// Return: true if friendship deleted
// false if friendship was not already recorded
//
public Boolean DeleteFriendship(Person P1, Person P2)
{
Friend F = GetFriendship(P1, P2);
if (F != null) return DeleteFriendship(F);
return false;
}
// Method: to delete and remove (from the database) all
friendship for the person
// Parameters: in Person
// Return: true if friendship deleted
// false if friendship was not already recorded
//
public static void DeleteFriendship(Person P1)
{
_FriendList.RemoveAll(Friend => (Friend.Person1 == P1 ||
Friend.Person2 == P1));
}
// Method: to determine if two persons are friends
// Parameters: in Person
// in Person
// Return: true if a friendship is recorded
// false if a friendship is not recorded
//
public Boolean AreFriends(Person P1, Person P2)
{
if (GetFriendship(P1, P2) != null) return true;
return false;
}
// Method: to write details of all Persons in the Dictionary
to the Console
// Parameters: None
// Return: None
//
public void ListFriendsToConsoleOf(Person P)
{
foreach (Friend F in _FriendList)
{
if (F.Person1 == P || F.Person2 == P)
{
F.WriteFriendshipToConsole();
}
}
}
// Method: to write details of all Persons in the Dictionary
to the Console
// Parameters: None
// Return: None
//
public void ListFriendsToConsole()
{
foreach (Friend F in _FriendList)
{
F.WriteFriendshipToConsole();
}
}
// Instance Methods
// None
}
//
-----------------------------------------------------------------------
public class PersonDatabase
{
// Class Data
static PersonCollection _Avatars = new PersonCollection();
EventListener listener = new EventListener(_Avatars);
//TODO - Locking - is this thread safe?
// Private Methods
// Method: Determine if a Person exists in the dictionary,
search on Person
// Parameters: in Person
// Return: true if the Person exists
// false if the Person does not exist
//
private Boolean PersonExists(Person Person)
{
if (_Avatars.Contains(Person))
{
return true;
}
return false;
}
// Public Methods
// Method: Determine if a person name exists in the Dictionary
and return the Person
// Parameters: in Name
// Return: Person if a person of that name exists
// null if a person of that name does not exist
//
public static Person GetPersonFromName(string Name)
{
foreach (Person person in _Avatars)
{
if (person.Name == Name)
{
return person;
}
}
return null;
}
// Method: to add a new person to the Dictionary (name must be
unique)
// Parameters: in Person
// Return: true if Person is successfully added
// false if a Person of the same name already
exists
//
public Boolean Add(Person Person)
{
if (PersonExists(Person)) return false; // requires mod to
check name
_Avatars.Add(Person);
return true;
}
// Method: to delete a person from the Dictionary by Person
// Parameters: in Person
// Return: true if person is successfully deleted
// false if the person cannot be located
//
public Boolean Delete(Person Person)
{
if (PersonExists(Person))
{
_Avatars.Remove(Person);
return true;
}
return false;
}
// Method: to write details of all Persons in the Dictionary
to the Console
// Parameters: None
// Return: None
//
public void WriteDictionaryToConsole()
{
foreach (Person person in _Avatars)
{
person.WritePersonToConsole();
Console.WriteLine();
}
}
// Instance Methods
// None
}
//
--------------------------------------------------------------------
class MainClass
{
public static void Main(string[] args)
{
PersonDatabase Avatars = new PersonDatabase();
FriendDatabase Friends = new FriendDatabase();
Person P1 = new Person("M1sha Dallin");
Person P2 = new Person("Sasha Nozaki");
Person P3 = new Person("Adelle Fitzgerald");
Person P4 = new Person("Bri Hasp");
Person P5 = new Person("Chaos Mandelbrot");
Person P6 = new Person("Francois Jacques");
Person P7 = new Person("Glida Pilote");
Person P8 = new Person("joepie Korobase");
Person P9 = new Person("Liv Leigh");
Person P10 = new Person("Manul Rotaru");
Person P11 = new Person("Schnoogge Broome");
Person P12 = new Person("Tonks Akina");
Friend F1, F2, F3, F4, F5, F6, F7, F8;
Friend Fa, Fb;
// Test Person and PersonDatabase classes
// Add
if (Avatars.Add(P1)) Console.WriteLine(P1.Name + " added
to the dictionary - test passed");
if (!Avatars.Add(P1)) Console.WriteLine(P1.Name + " not
added to the dictionary (duplicate) - test passed");
if (Avatars.Add(P2)) Console.WriteLine(P2.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P3)) Console.WriteLine(P3.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P4)) Console.WriteLine(P4.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P5)) Console.WriteLine(P5.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P6)) Console.WriteLine(P6.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P7)) Console.WriteLine(P7.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P8)) Console.WriteLine(P8.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P9)) Console.WriteLine(P9.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P10)) Console.WriteLine(P10.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P11)) Console.WriteLine(P11.Name + " added
to the dictionary - test passed");
if (Avatars.Add(P12)) Console.WriteLine(P12.Name + " added
to the dictionary - test passed");
Console.WriteLine("\n12 names should be listed below");
Avatars.WriteDictionaryToConsole();
Console.WriteLine();
// Delete
if (Avatars.Delete(P12)) Console.WriteLine(P12.Name + "
deleted from dictionary - test passed");
if (!Avatars.Delete(P12)) Console.WriteLine(P12.Name + "
has already been deleted - test passed");
Console.WriteLine("\n11 names should be listed below");
Avatars.WriteDictionaryToConsole();
// GetPersonFromName
if (PersonDatabase.GetPersonFromName("M1sha Dallin") ==
P1) Console.WriteLine(P1.Name + "'s object was located by name - test
passed");
if (PersonDatabase.GetPersonFromName("Tonks Akina") ==
null) Console.WriteLine("A deleted person was not found - test
passed");
// Test Friend and FriendDatabase
// MakeFriendship
F1 = Friends.MakeFriendship(P1, P2);
F2 = Friends.MakeFriendship(P1, P3);
F3 = Friends.MakeFriendship(P1, P4);
F4 = Friends.MakeFriendship(P1, P5);
F5 = Friends.MakeFriendship(P6, P1);
F6 = Friends.MakeFriendship(P7, P1);
F7 = Friends.MakeFriendship(P8, P1);
F8 = Friends.MakeFriendship(P5, P6);
// ListFriendsToConsole
Console.WriteLine("\n8 Friends relationships should be
listed below");
Friends.ListFriendsToConsole();
//List FriendsToConsoleOf
Console.WriteLine("\n\n7 Friends relationships for M1sha
should be listed below");
Friends.ListFriendsToConsoleOf(P1);
Console.WriteLine("\n\n1 Friends relationships for Glida
should be listed below");
Friends.ListFriendsToConsoleOf(P7);
// FindFriendship
Fa = Friends.GetFriendship(P1, P5);
Fb = Friends.GetFriendship(P5, P1);
if (Fa == Fb && Fa == F4) Console.WriteLine("\nFriend
relationship for " + P1.Name + " and " + P5.Name + " found - test
passed");
// DeleteFriendship
if (Friends.DeleteFriendship(P1, P2)) Console.WriteLine
("\nFriendship deleted for " + P1.Name + " and " + P2.Name + " - test
passed");
if (Friends.DeleteFriendship(P3, P1)) Console.WriteLine
("\nFriendship deleted for " + P6.Name + " and " + P5.Name + " - test
passed");
Console.WriteLine("\n\n6 Friends relationships should be
listed below");
Friends.ListFriendsToConsole();
Console.WriteLine("\n\n5 Friends relationships for M1sha
should be listed below");
Friends.ListFriendsToConsoleOf(P1);
// AreFriends
if (Friends.AreFriends(P1, P4)) Console.WriteLine
("\nFriendship found for " + P1.Name + " and " + P4.Name + " - test
passed");
if (!Friends.AreFriends(P1, P2)) Console.WriteLine
("\nFriendship not found for " + P1.Name + " and " + P2.Name + " -
test passed");
// Delete Person and confirm propagation of deleted
friendships
if (Avatars.Delete(P1)) Console.WriteLine("\nP1 (M1sha)
Deleted");
Console.WriteLine("1 Friend relationship should remain (P5
& P6) Francois & Chaos");
Friends.ListFriendsToConsole();
}
}
}
http://www.pastebin.ca/1353866
using System;
namespace Calculator
{
class MainClass
{
public static void Main(string[] args)
{
string lineA = Console.ReadLine();
int a = int.Parse(lineA);
string lineB = Console.ReadLine();
int b = int.Parse(lineB);
Console.WriteLine("Sum of {0} and {1} = {2}", a, b, a+b);
}
}
}
http://www.pastebin.ca/1353867
using System;
namespace ConsoleCalculator
{
class Calculator
{
static void Main(string[] args)
{
int i, j;
Console.Write("Enter the first digit: ");
i = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the second digit: ");
j = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The sum of your digits is: " +
Convert.ToString(i + j));
}
}
}
http://www.pastebin.ca/1353874
using System;
namespace Calculator
{
class Program
{
public static bool IsInt(string s)
{
try
{
int.Parse(s);
return true;
}
catch
{
return false;
}
}
static void Main(string[] args)
{
string S, T;
Console.Write("Enter the first number: ");
S = Console.ReadLine();
Console.Write("Enter the second number: ");
T = Console.ReadLine();
if (IsInt(S) && IsInt(T))
{
Console.WriteLine("The sum is: {0}", Convert.ToInt32
(S) + Convert.ToInt32(T));
}
else
{
Console.WriteLine("Numbers were not entered");
}
}
}
}
http://www.pastebin.ca/1353880
using System;
namespace Calculator
{
class MainClass
{
public static void Main(string[] args)
{
string lineA = Console.ReadLine();
int a;
if(!int.TryParse(lineA, out a))
{
Console.WriteLine("The number must be an integer");
return;
}
string lineB = Console.ReadLine();
int b;
if(!int.TryParse(lineB, out b))
{
Console.WriteLine("The number must be an integer");
return;
}
Console.WriteLine("Sum of {0} and {1} = {2}", a, b, a+b);
}
}
}