OSG Community College C# for Programmers Class #5 Log 03/10/2009

0 views
Skip to first unread message

AdelleF

unread,
Mar 17, 2009, 3:29:19 PM3/17/09
to OSG Community College
Pastebins are at the bottom of the chat log.

[2009/03/10 12:11] M1sha Dallin: Hi Adelle
[2009/03/10 12:11] Adelle Fitzgerald: hiya, osrry im late
[2009/03/10 12:11] Snowdrop Short: hiya Adelle :-)
[2009/03/10 12:11] Snowdrop Short: we were just talking about what we
should cover today
[2009/03/10 12:12] Adelle Fitzgerald: gotcha
[2009/03/10 12:12] Snowdrop Short: I guess you've all looked at
Dictionary and List?
[2009/03/10 12:12] Snowdrop Short: right?
[2009/03/10 12:12] M1sha Dallin: yep
[2009/03/10 12:12] Adelle Fitzgerald: just a little
[2009/03/10 12:13] M1sha Dallin: and raised a few exceptions :-)
[2009/03/10 12:13] Snowdrop Short smiles
[2009/03/10 12:13] Snowdrop Short: that's a must
[2009/03/10 12:13] Snowdrop Short: at least one per session
[2009/03/10 12:13] M1sha Dallin: it wasn't intentional
[2009/03/10 12:13] Snowdrop Short: the reason why I want to to
explore that
[2009/03/10 12:14] Snowdrop Short: it that, the surrounding framework
is just like the functions in lsl
[2009/03/10 12:14] Snowdrop Short: it's not really part of the
language as such
[2009/03/10 12:14] Snowdrop Short: but you need to know the most
important ones
[2009/03/10 12:15] Snowdrop Short: Console .. is pretty important
[2009/03/10 12:15] Snowdrop Short: becasue it provides basic input
and output
[2009/03/10 12:15] Snowdrop Short: Dictionary and List because those
are the two most common containers
[2009/03/10 12:16] Snowdrop Short: and almost always you end up
needing some kind of container
[2009/03/10 12:16] M1sha Dallin: The Indexed List was also useful
[2009/03/10 12:17] M1sha Dallin: saved replicating data
[2009/03/10 12:17] Snowdrop Short: but what I really wanted to talk
about was delegates
[2009/03/10 12:18] Snowdrop Short: delegates and events are some of
the strong points of c#
[2009/03/10 12:18] Snowdrop Short: let me quickly grab some code on
pastebin for you
[2009/03/10 12:18] Adelle Fitzgerald: kk
[2009/03/10 12:19] Adelle Fitzgerald: list is almost identicle to the
lsl list
[2009/03/10 12:20] M1sha Dallin: Does lsl list index? My lsl is poor
[2009/03/10 12:21] Adelle Fitzgerald: i think so
[2009/03/10 12:21] Adelle Fitzgerald: lemme quickly check
[2009/03/10 12:22] Adelle Fitzgerald: hmm, maybe not
[2009/03/10 12:22] M1sha Dallin: How do you find the entry you are
looking for in an lsl list?
[2009/03/10 12:24] Adelle Fitzgerald: you can refernce it by its ..
umm, cant think of the word.. but each record in the list has a
numeric, so for a list that had 'red,orange', then red=0 orange=1
[2009/03/10 12:24] Adelle Fitzgerald: you can also do a direct find
on an lsl list too
[2009/03/10 12:24] M1sha Dallin: Ah OK
[2009/03/10 12:24] Adelle Fitzgerald: a direct find is slow though
[2009/03/10 12:24] Starky Rubble: the word is index maybe
[2009/03/10 12:24] Starky Rubble: hi all
[2009/03/10 12:24] Adelle Fitzgerald: oh
[2009/03/10 12:24] Adelle Fitzgerald: lol
[2009/03/10 12:24] Adelle Fitzgerald: hiya :)
[2009/03/10 12:25] M1sha Dallin: Hi Starky
[2009/03/10 12:25] M1sha Dallin: welcome back
[2009/03/10 12:25] Starky Rubble: it would be index in other
languages
[2009/03/10 12:25] Starky Rubble: I parked so I could catch up
[2009/03/10 12:25] Starky Rubble: as you know its a hard time for me
[2009/03/10 12:25] Snowdrop Short: wb Starky
[2009/03/10 12:25] Starky Rubble: hi
[2009/03/10 12:26] Snowdrop Short: so
[2009/03/10 12:26] Starky Rubble: I agree that we need to know about
private and all btw :)
[2009/03/10 12:26] Snowdrop Short: in c# a delegate is used to pass
some code as a parameter
[2009/03/10 12:26] Starky Rubble: ok
[2009/03/10 12:27] Snowdrop Short: just like you can pass variables,
constants
[2009/03/10 12:27] Snowdrop Short: into a method
[2009/03/10 12:27] Snowdrop Short: in the same manner, you can pass
code into the method
[2009/03/10 12:27] Snowdrop Short: and then have the method execute
that code
[2009/03/10 12:27] Starky Rubble: hmm
[2009/03/10 12:28] Snowdrop Short looks at Starky
[2009/03/10 12:28] Snowdrop Short: you frown?
[2009/03/10 12:28] Starky Rubble: no no - sounds odd but I am
listening
[2009/03/10 12:28] Snowdrop Short: ok
[2009/03/10 12:29] Snowdrop Short: in a way it is kind of natural
[2009/03/10 12:29] Snowdrop Short: why should we limit ourselves to
just passing variables to a method
[2009/03/10 12:29] Snowdrop Short: who says you cannot pass code?
[2009/03/10 12:30] Snowdrop Short: after all code is stored in the
memory of the computer, just like anything else
[2009/03/10 12:30] Starky Rubble: kinda like a goto maybe
[2009/03/10 12:30] Snowdrop Short: let me give you and example
[2009/03/10 12:31] Snowdrop Short: one of the most common things in
modern programming is events
[2009/03/10 12:31] Snowdrop Short: you have a program wating for
something to happen
[2009/03/10 12:31] Snowdrop Short: like a button being pressed on a
gui
[2009/03/10 12:32] Snowdrop Short: and then it sends of an "event",
hoping that the even handler knows what to do with it
[2009/03/10 12:32] Adelle Fitzgerald nods
[2009/03/10 12:32] Starky Rubble: right
[2009/03/10 12:32] Snowdrop Short: the way this is done in c# is that
we pass a piece of code to the program that waits for the button press
[2009/03/10 12:33] Snowdrop Short: and the monitoring program then
runs the piece of code we gave to it
[2009/03/10 12:33] Snowdrop Short: another example
[2009/03/10 12:33] Snowdrop Short: from our group project
[2009/03/10 12:34] Snowdrop Short: lets say that we had a method
which took a piece of code, and then ran that code on every member in
a group
[2009/03/10 12:34] Snowdrop Short: so grouplist had a method
[2009/03/10 12:34] Snowdrop Short: DoWork(.....)
[2009/03/10 12:35] Snowdrop Short: and in the parameter to DoWork
would be some code, which acted on every group in the group list
[2009/03/10 12:36] Snowdrop Short: once we had the code straigth for
iterating through the list, we could reuse it for several different
things
[2009/03/10 12:36] Snowdrop Short: resetting the member list
[2009/03/10 12:36] Starky Rubble: Snding notices
[2009/03/10 12:36] Snowdrop Short: yes
[2009/03/10 12:36] Snowdrop Short: all sorts of things
[2009/03/10 12:36] Snowdrop Short: a delegate
[2009/03/10 12:36] Snowdrop Short: in c# is just that
[2009/03/10 12:37] Snowdrop Short: a piece of code which can be
passed as a parameter
[2009/03/10 12:37] Snowdrop Short: http://www.pastebin.ca/1357624
[2009/03/10 12:37] Snowdrop Short: here is the first go of a delegate
[2009/03/10 12:37] Snowdrop Short: let me know when you are ready
[2009/03/10 12:39] Adelle Fitzgerald: k, im good
[2009/03/10 12:39] M1sha Dallin: yep
[2009/03/10 12:39] Starky Rubble: ok
[2009/03/10 12:39] Snowdrop Short: the first thing to note is in line
35
[2009/03/10 12:40] Snowdrop Short: here we define how a delegate of
type "AdditionalInfo" lookslike
[2009/03/10 12:40] Snowdrop Short: in this case, it should look like
a method
[2009/03/10 12:40] Snowdrop Short: which returns a string
[2009/03/10 12:41] Snowdrop Short: and takes no parameters
[2009/03/10 12:41] Snowdrop Short: it can have any name, but the
"shape" of the method should match "AdditionalInfo"
[2009/03/10 12:42] Snowdrop Short: this is only a declaration, so all
parties agree on what kind of code can be passed as a parameter
[2009/03/10 12:42] Snowdrop Short: next point of interest is in line
51
[2009/03/10 12:43] Snowdrop Short: here I've changed the
"WriteToConsole" method so it accepts a delegate of type
"AdditionalInfo"
[2009/03/10 12:43] Snowdrop Short: as a parameter
[2009/03/10 12:43] Snowdrop Short: and in line 54 it is being used
[2009/03/10 12:44] Snowdrop Short: note that the parameter has the
name "message"
[2009/03/10 12:44] Starky Rubble: K
[2009/03/10 12:44] Snowdrop Short: and that the parameters after the
"message" in line 54 instructs the runtime to execute the passed
delegate
[2009/03/10 12:45] Snowdrop Short: in line 68-72 I've defined a
method, which matches the signature of "AdditionalInfo"
[2009/03/10 12:46] Snowdrop Short: it is important that it matches
the "shape" or "signature"
[2009/03/10 12:46] Snowdrop Short: the actual name, in this case
"Bubble" is not important
[2009/03/10 12:46] Snowdrop Short: as long as it returns a string,
and takes no input
[2009/03/10 12:47] Snowdrop Short: in line 85
[2009/03/10 12:47] Starky Rubble: but the method could have calced or
fetched the string?
[2009/03/10 12:47] Snowdrop Short: yes, read it from the console or a
file
[2009/03/10 12:47] Snowdrop Short: as long as it returned a string
[2009/03/10 12:47] Starky Rubble: ok
[2009/03/10 12:47] Starky Rubble: right
[2009/03/10 12:48] Snowdrop Short: in line 85, a new delegate is
created
[2009/03/10 12:48] Snowdrop Short: and passed as a parameter to the
"WriteToConsole" method
[2009/03/10 12:48] Snowdrop Short: so when WriteToConsole executes
[2009/03/10 12:49] Snowdrop Short: it writes
[2009/03/10 12:49] Snowdrop Short: Description=For cool people, #of
Members 0bubble
[2009/03/10 12:49] Snowdrop Short: note the "bubble" at the end of
the line
[2009/03/10 12:50] Snowdrop Short: so
[2009/03/10 12:50] Snowdrop Short: step on on delegate
[2009/03/10 12:50] Snowdrop Short: are you ok with it so far?
[2009/03/10 12:51] Starky Rubble: yes
[2009/03/10 12:51] Adelle Fitzgerald: i think so, just trying to get
my head around it by looking at the code
[2009/03/10 12:51] Snowdrop Short nods
[2009/03/10 12:51] M1sha Dallin: yep
[2009/03/10 12:52] Snowdrop Short: delegates are a bit confusing in
the beginning
[2009/03/10 12:52] Snowdrop Short: not that many people feel
comfortable with passing code as parameters to a method
[2009/03/10 12:52] Snowdrop Short: at least at first
[2009/03/10 12:53] Starky Rubble: It seems to me they act like old
school functions but forced into a data type wrapper and passed in to
the method
[2009/03/10 12:53] Snowdrop Short: "old school function pointers"
[2009/03/10 12:53] Adelle Fitzgerald: i understand the concept ot it,
it is pretty much what I was asking, i think last week, about passing
code as an object to another object, but i got the terminology wrong,
this is what I was meaning
[2009/03/10 12:53] Starky Rubble: right on lol
[2009/03/10 12:53] Snowdrop Short: but yes, intiallly they look that
way
[2009/03/10 12:54] Snowdrop Short: but, they are much more powerfull
[2009/03/10 12:54] Starky Rubble: all that really matters is that you
get the shape (data type) set up correctly
[2009/03/10 12:54] Snowdrop Short: yes
[2009/03/10 12:55] Snowdrop Short: that's the important thing
[2009/03/10 12:55] Starky Rubble: iok Im with you
[2009/03/10 12:55] Snowdrop Short: the shape must match perfectly
[2009/03/10 12:55] Snowdrop Short: lets try to make a small
improvement to our delegate
[2009/03/10 12:56] Starky Rubble: it makes sense because the passing
of objects or delegates is all about knowing the 'shape'
[2009/03/10 12:56] Adelle Fitzgerald: ahh, i think i understand the
code now, the way 'bubble' is passed over
[2009/03/10 13:01] Starky Rubble: hmmm
[2009/03/10 13:01] Adelle Fitzgerald: pastebinning I expect
[2009/03/10 13:01] Snowdrop Short: sorry about that
[2009/03/10 13:01] Adelle Fitzgerald: hehe np
[2009/03/10 13:01] Snowdrop Short: I had a runtime
[2009/03/10 13:01] Snowdrop Short: error
[2009/03/10 13:01] Snowdrop Short: I hadn't anticipated
[2009/03/10 13:02] Starky Rubble: oopsie lol
[2009/03/10 13:02] Snowdrop Short: little point in making it more
confusing than is necessary
[2009/03/10 13:02] Snowdrop Short: http://www.pastebin.ca/1357657
[2009/03/10 13:02] Snowdrop Short: this is just a minor change
[2009/03/10 13:03] Snowdrop Short: but making the code execution more
explicit
[2009/03/10 13:03] Snowdrop Short: I changed the signature in line 35
[2009/03/10 13:03] Snowdrop Short: now it takes an integer as a
parameter
[2009/03/10 13:03] Snowdrop Short: jumping to line 68
[2009/03/10 13:04] Snowdrop Short: you can see that I changed the
"Bubble" method
[2009/03/10 13:04] Snowdrop Short: to match the signature, so we can
use it as a delegate
[2009/03/10 13:04] Snowdrop Short: line 85 hasn't been chagned
[2009/03/10 13:04] Snowdrop Short: changed
[2009/03/10 13:04] Snowdrop Short: but line 54
[2009/03/10 13:04] Snowdrop Short: has been changed
[2009/03/10 13:05] Snowdrop Short: because the delegate expects an
integer parameter
[2009/03/10 13:05] Snowdrop Short: and that parameter must be
supplied from somewhere
[2009/03/10 13:05] Adelle Fitzgerald: right
[2009/03/10 13:06] Snowdrop Short: and right now ... it can only come
from the place where we invoke the delegate
[2009/03/10 13:06] Snowdrop Short: and the resulting output is as
you'd expect
[2009/03/10 13:06] Snowdrop Short: Description=For cool people, #of
Members 0 Bubble(5)
[2009/03/10 13:06] Snowdrop Short: where the number 5 is the one from
WriteToConsole
[2009/03/10 13:07] Adelle Fitzgerald: so Static String Bubble, could
be quite complex, that gatheres information from other places and
reuses that code each time, with say the variables changing for each
[2009/03/10 13:07] Snowdrop Short: yes
[2009/03/10 13:07] Adelle Fitzgerald: each time it is used that is
[2009/03/10 13:08] Snowdrop Short: it is a piece of code in it's own
right
[2009/03/10 13:08] Snowdrop Short: it could call other methods
[2009/03/10 13:08] Adelle Fitzgerald nods
[2009/03/10 13:08] Snowdrop Short: it is code, just like any other
code
[2009/03/10 13:09] Starky Rubble: what happens in the delegate stays
in the delegate and all is well as long as the return matches the
shape
[2009/03/10 13:09] Adelle Fitzgerald: this seems similar to a
function, but is more efficient?
[2009/03/10 13:09] Starky Rubble: You mentioned changing the
'signature' - did I miss something?
[2009/03/10 13:10] Snowdrop Short: the delgate can do what ever it
wants, it might call back into group, and change group
[2009/03/10 13:10] Snowdrop Short: actually there is a penalty to pay
for using delegates
[2009/03/10 13:10] Snowdrop Short: in performance
[2009/03/10 13:10] Snowdrop Short: but for most purposes, it doesn't
really matter
[2009/03/10 13:11] Snowdrop Short: yes, the signature is now
[2009/03/10 13:11] Snowdrop Short: "string AdditionalInfo(int n)"
[2009/03/10 13:11] Snowdrop Short: the "int n"
[2009/03/10 13:11] Snowdrop Short: is the change
[2009/03/10 13:11] Starky Rubble: ok so its the definition of the
delegate?
[2009/03/10 13:11] Snowdrop Short: yes
[2009/03/10 13:11] Snowdrop Short: the definition
[2009/03/10 13:11] Starky Rubble: is that the proper term?
[2009/03/10 13:12] Snowdrop Short: signature is a bit more formal
[2009/03/10 13:12] Starky Rubble: oh ok
[2009/03/10 13:12] Snowdrop Short: but that is the correct term
[2009/03/10 13:12] Snowdrop Short: ok ...
[2009/03/10 13:12] Snowdrop Short: is everyone with me so far?
[2009/03/10 13:12] Adelle Fitzgerald nods
[2009/03/10 13:13] Starky Rubble: yep
[2009/03/10 13:13] Snowdrop Short: M1sha?
[2009/03/10 13:13] Snowdrop Short: let me challenge another
conventional wisdom
[2009/03/10 13:14] Snowdrop Short: which has dissapeard with c#
[2009/03/10 13:14] Snowdrop Short: why does code need to be in a
method
[2009/03/10 13:14] M1sha Dallin: yep - sorry
[2009/03/10 13:15] Snowdrop Short: couldn't we declare a local
variable .. which contained code rather than numbers or strings or
dates, etc.
[2009/03/10 13:15] M1sha Dallin: We can? - Anonymous something rings
a bell
[2009/03/10 13:16] Starky Rubble: I suppose it all just addresses and
allocations in the end
[2009/03/10 13:16] Snowdrop Short: not anonymous
[2009/03/10 13:16] Snowdrop Short: although we can do that as well
[2009/03/10 13:16] Snowdrop Short: but real variables
[2009/03/10 13:17] Snowdrop Short: just with code, rather than
traditional data
[2009/03/10 13:17] Adelle Fitzgerald: i dont understand that, it
sounds silly. you cant use code in a variable... its just a variable,
a string, or int...
[2009/03/10 13:17] Starky Rubble: why not! We're all friends here lol
[2009/03/10 13:18] Snowdrop Short: yes
[2009/03/10 13:18] Starky Rubble: I hear you tho Adelle it does sound
odd
[2009/03/10 13:18] Snowdrop Short: actually that way we can move code
around
[2009/03/10 13:19] Starky Rubble: and write self modifiying programs
lol
[2009/03/10 13:19] M1sha Dallin: ouch
[2009/03/10 13:19] Adelle Fitzgerald: they would only be modifing
within the parameters of the code itself
[2009/03/10 13:20] Starky Rubble: ouch indeed
[2009/03/10 13:20] Snowdrop Short: here is a small sample
[2009/03/10 13:21] Snowdrop Short: http://www.pastebin.ca/1357672
[2009/03/10 13:21] Snowdrop Short: let me know when you've got the
code
[2009/03/10 13:22] Adelle Fitzgerald: got it
[2009/03/10 13:22] Starky Rubble: yes
[2009/03/10 13:22] M1sha Dallin: yep
[2009/03/10 13:22] Snowdrop Short: ok
[2009/03/10 13:22] Snowdrop Short: the biggest change ....
[2009/03/10 13:23] Snowdrop Short: I have removed the old "static
string Bubble...." method
[2009/03/10 13:23] Snowdrop Short: and created a new one, inside the
main method
[2009/03/10 13:23] Snowdrop Short: in line 70
[2009/03/10 13:24] Snowdrop Short: I declare a variable of type
"Group.AdditionalInfo" with the name "bubble"
[2009/03/10 13:24] Snowdrop Short: and assign it a value
[2009/03/10 13:24] Snowdrop Short: just as if I had written
[2009/03/10 13:24] Snowdrop Short: int n = 7;
[2009/03/10 13:24] Snowdrop Short: but now the "7" part is code of
type delegate
[2009/03/10 13:25] Snowdrop Short: so I assign it a value of "delegate
(int n) { ..code...};
[2009/03/10 13:25] Snowdrop Short: that is by far the biggest change
[2009/03/10 13:26] Snowdrop Short: then in line 84
[2009/03/10 13:26] Snowdrop Short: it used to say "new
Group.AddtionalInfo(Bubble)"
[2009/03/10 13:27] Snowdrop Short: but the "new ..." stuff was used
only to create a delegate
[2009/03/10 13:27] Snowdrop Short: but bubble is already defined as a
delegate
[2009/03/10 13:27] Snowdrop Short: so we don't need to do that any
more
[2009/03/10 13:28] Snowdrop Short: so ... what good it that?
[2009/03/10 13:28] Starky Rubble: Ok now I'm lost
[2009/03/10 13:28] Starky Rubble: 7?
[2009/03/10 13:28] Starky Rubble: where?
[2009/03/10 13:28] Snowdrop Short: sorry .... it was just an example
[2009/03/10 13:28] Starky Rubble: oh
[2009/03/10 13:28] Snowdrop Short: when you declare a variable of
type int
[2009/03/10 13:28] Snowdrop Short: int n;
[2009/03/10 13:28] Starky Rubble: yes
[2009/03/10 13:29] Snowdrop Short: it is legal to immediately assign
it an intial value, like "7"
[2009/03/10 13:29] Snowdrop Short: by writing
[2009/03/10 13:29] Snowdrop Short: int n = 7;
[2009/03/10 13:29] Starky Rubble: yes
[2009/03/10 13:29] Snowdrop Short: we just did a very similar thing
[2009/03/10 13:29] Snowdrop Short: we declared a variable "bubble" of
type "Group.AdditionalInfo"
[2009/03/10 13:30] Snowdrop Short: and initialized it's value
[2009/03/10 13:30] Snowdrop Short: but this time the value is a piece
of code
[2009/03/10 13:30] Snowdrop Short: the basic form is the same
[2009/03/10 13:31] Snowdrop Short: Group.AdditionalInfo bubble = ---
some code ----
[2009/03/10 13:31] M1sha Dallin: This way is more flexible - can use
a group object and get it to so something different with the delegate.
[2009/03/10 13:31] Snowdrop Short: int n = --- some value ---
[2009/03/10 13:31] M1sha Dallin: not possible on a single group
object the other way - I think
[2009/03/10 13:32] Snowdrop Short: yes .. like I said, the first
impression is "yawn ... function pointers, just with a new name"
[2009/03/10 13:32] Snowdrop Short: but delgates can do so much more
[2009/03/10 13:32] Snowdrop Short: the best is yet to come :-)
[2009/03/10 13:33] Starky Rubble: uh oh
[2009/03/10 13:33] M1sha Dallin: :-)
[2009/03/10 13:33] Snowdrop Short: but for now, I want to make sure
that we're all on the same page
[2009/03/10 13:34] Starky Rubble: I'm there... barely lol
[2009/03/10 13:34] Snowdrop Short: http://www.pastebin.ca/1357682
[2009/03/10 13:34] Snowdrop Short: just a minor change
[2009/03/10 13:35] Snowdrop Short: to exemplify a bit
[2009/03/10 13:35] Snowdrop Short: let me know when you have it
[2009/03/10 13:35] M1sha Dallin: yep
[2009/03/10 13:36] Adelle Fitzgerald: got it
[2009/03/10 13:36] Starky Rubble: oh sorry
[2009/03/10 13:36] Starky Rubble: yes
[2009/03/10 13:36] Snowdrop Short: ok
[2009/03/10 13:36] Snowdrop Short smiles
[2009/03/10 13:37] Snowdrop Short: in line 75
[2009/03/10 13:37] Snowdrop Short whispers: I've declared yet another
variable of type "Group.AdditionalInfo"
[2009/03/10 13:37] Snowdrop Short: called "b2"
[2009/03/10 13:37] Snowdrop Short: and in line 77
[2009/03/10 13:37] Snowdrop Short: b2 gets assigned the value of
bubble
[2009/03/10 13:37] Snowdrop Short: and then in line 88
[2009/03/10 13:38] Snowdrop Short: instead of passing the contents of
the variable bubble
[2009/03/10 13:38] Snowdrop Short: I pass the contents of b2
[2009/03/10 13:38] Snowdrop Short: it yieds the same result, because
b2 points to the same chunk of code as bubble
[2009/03/10 13:39] Snowdrop Short: but just to make it clear, that we
are really working on variables, containing code
[2009/03/10 13:39] Adelle Fitzgerald: gotcha
[2009/03/10 13:39] M1sha Dallin: yep
[2009/03/10 13:39] Snowdrop Short: that is part of the strength of c#
[2009/03/10 13:40] Snowdrop Short: code can be passed around just
like anything else
[2009/03/10 13:41] Snowdrop Short: any questions so far?
[2009/03/10 13:41] M1sha Dallin: nope - I'm fine
[2009/03/10 13:41] Starky Rubble: b2 or not b2 - that is the question
lol
[2009/03/10 13:41] Adelle Fitzgerald: lol
[2009/03/10 13:41] Snowdrop Short: lol
[2009/03/10 13:41] M1sha Dallin: :-)
[2009/03/10 13:41] Snowdrop Short: ok .. but what have we actually
gained
[2009/03/10 13:42] Snowdrop Short: nothing much, except, now suddenly
our nice method has some totally unrelated code embedded into it
[2009/03/10 13:42] Snowdrop Short: so you might think of this as a
step back
[2009/03/10 13:42] Adelle Fitzgerald: i do a bit
[2009/03/10 13:42] Snowdrop Short: because .. it isn't pretty
[2009/03/10 13:42] Snowdrop Short: not pretty at all
[2009/03/10 13:43] Starky Rubble: true, that
[2009/03/10 13:43] Adelle Fitzgerald: i can sorta see its potential,
but in this example seems pointless
[2009/03/10 13:43] Snowdrop Short: the exciting part in this is that
the code is declared inside the method "method"
[2009/03/10 13:43] Starky Rubble: but bubble could actually do
something
[2009/03/10 13:44] Snowdrop Short: when we had it defined in the
class, it could only reach class members
[2009/03/10 13:44] Starky Rubble: oh
[2009/03/10 13:44] Snowdrop Short: but when it is defined inside the
method
[2009/03/10 13:44] Snowdrop Short: it can access the local variables
of the method
[2009/03/10 13:45] Adelle Fitzgerald: ohh, i see that now
[2009/03/10 13:46] Snowdrop Short: http://www.pastebin.ca/1357696
[2009/03/10 13:46] Snowdrop Short: let me know when you have the code
[2009/03/10 13:46] Adelle Fitzgerald: got it
[2009/03/10 13:46] Starky Rubble: ok
[2009/03/10 13:47] M1sha Dallin: ok
[2009/03/10 13:47] Snowdrop Short: great
[2009/03/10 13:47] Snowdrop Short: :-)
[2009/03/10 13:47] Snowdrop Short: in line 70
[2009/03/10 13:47] Snowdrop Short: I added a declaration of a local
variable m
[2009/03/10 13:47] Snowdrop Short: and initialized it with the value
of 7
[2009/03/10 13:47] Snowdrop Short: and then inside the "bubble"
delegate, I use the value of "m"
[2009/03/10 13:48] Snowdrop Short: as part of the output
[2009/03/10 13:48] Snowdrop Short: Description=For cool people, #of
Members 0 Bubble(5)[7]
[2009/03/10 13:48] Adelle Fitzgerald nods
[2009/03/10 13:48] Starky Rubble: yes
[2009/03/10 13:48] M1sha Dallin: yep
[2009/03/10 13:48] Snowdrop Short: by declaring it inside the method,
I gained the opportunity of referencing variables local to "main"
[2009/03/10 13:49] Starky Rubble: ok I see that
[2009/03/10 13:49] Snowdrop Short: so I can actually decide what kind
of access to local variables I want to give a delegate
[2009/03/10 13:50] Snowdrop Short: I can declare it as a method on a
class
[2009/03/10 13:50] Snowdrop Short: that way it can only access class
members and methods
[2009/03/10 13:50] Snowdrop Short: or if I declare it inside a
method, it can access not only the class members and methods
[2009/03/10 13:51] Snowdrop Short: but also the local variables
inside the method
[2009/03/10 13:51] Starky Rubble: and either way it is still a
delegate
[2009/03/10 13:51] Snowdrop Short: yes
[2009/03/10 13:51] Snowdrop Short: it is still a delegate
[2009/03/10 13:52] Starky Rubble: ok
[2009/03/10 13:52] Snowdrop Short: I might have to create it
explicitly by using "new Group.AdditionalInfo"
[2009/03/10 13:52] Snowdrop Short: or just the name
[2009/03/10 13:52] Snowdrop Short: depending on how I declared the
delegate
[2009/03/10 13:53] Snowdrop Short: ok
[2009/03/10 13:53] Snowdrop Short: lets return back to the definition
we made in line 71
[2009/03/10 13:54] Snowdrop Short: because I skipped something
[2009/03/10 13:54] Snowdrop Short: which I'd like to return to
[2009/03/10 13:54] Snowdrop Short: because I said "we initialize the
delegate"
[2009/03/10 13:54] Snowdrop Short: with a value of a piece of code
[2009/03/10 13:55] Snowdrop Short: so the lines 71 - 74
[2009/03/10 13:55] Snowdrop Short: actually consists of two things
[2009/03/10 13:55] Snowdrop Short: a declaration of bubble
[2009/03/10 13:55] Snowdrop Short: just like we declared b2
[2009/03/10 13:55] Snowdrop Short: and then an assignment of an
immediate value
[2009/03/10 13:55] Snowdrop Short: delegate(int n) { .....};
[2009/03/10 13:56] Snowdrop Short: with an "assignment" = operator
[2009/03/10 13:56] Starky Rubble: right
[2009/03/10 13:57] Snowdrop Short: so one way to think of it that we
can create and immediate valued delegate by writing
[2009/03/10 13:57] Snowdrop Short: "delegate(int n) { ....};
[2009/03/10 13:57] Snowdrop Short: and the compiler looks at our
code, and determines that we return a string
[2009/03/10 13:58] Snowdrop Short: hence it matches the signature of
"Group.AdditionalInfo"
[2009/03/10 13:58] Starky Rubble: ok
[2009/03/10 13:58] Snowdrop Short: but if that is so
[2009/03/10 13:59] Snowdrop Short: ie ... that we can create an
immediate value, matching a delegate
[2009/03/10 13:59] Snowdrop Short: then couldn't we just replace the
"b2" part of "g.WriteToConsole"
[2009/03/10 13:59] Snowdrop Short: with the immediate valued delegate
[2009/03/10 14:00] Snowdrop Short: ?
[2009/03/10 14:00] M1sha Dallin: as in g.WriteToConsole(delegate(int
n) { ....}); ?
[2009/03/10 14:00] Snowdrop Short: http://www.pastebin.ca/1357709
[2009/03/10 14:00] Snowdrop Short: yes
[2009/03/10 14:00] Snowdrop Short: here is a piece of code
[2009/03/10 14:00] Snowdrop Short: where I did just taht
[2009/03/10 14:00] Snowdrop Short: that
[2009/03/10 14:00] M1sha Dallin: :-)
[2009/03/10 14:00] Snowdrop Short: try to run it
[2009/03/10 14:01] Snowdrop Short: it works
[2009/03/10 14:01] Snowdrop Short: let me know when you are ready
[2009/03/10 14:01] M1sha Dallin: yep
[2009/03/10 14:01] Adelle Fitzgerald: yep
[2009/03/10 14:02] Snowdrop Short: so
[2009/03/10 14:02] Snowdrop Short: we've had a delegate we called
"Bubble"
[2009/03/10 14:02] Snowdrop Short: and one we called
[2009/03/10 14:02] Snowdrop Short: bubble
[2009/03/10 14:02] Snowdrop Short: and
[2009/03/10 14:02] Snowdrop Short: b2
[2009/03/10 14:03] Snowdrop Short: what name does our latest delegate
have?
[2009/03/10 14:03] Starky Rubble: ok
[2009/03/10 14:03] Starky Rubble: none
[2009/03/10 14:03] M1sha Dallin: anonymous?
[2009/03/10 14:03] Snowdrop Short: yes .. this is what is called an
anonymous delegate
[2009/03/10 14:04] Snowdrop Short: it is frequently used when writing
eventhandlers for gui code
[2009/03/10 14:04] Starky Rubble: it would be easy to write "neraly
impossible to read" codethat way lol
[2009/03/10 14:04] Snowdrop Short: yes
[2009/03/10 14:05] Snowdrop Short: so it is a thing which should be
used in the right circumstances
[2009/03/10 14:05] Snowdrop Short: otherwise your code becomes
impossible to read
[2009/03/10 14:05] Snowdrop Short: but lets say you have a calculator
display on a gui
[2009/03/10 14:06] Snowdrop Short: with a button for each of the 10
digits
[2009/03/10 14:06] Snowdrop Short: each operation per push is very
simple
[2009/03/10 14:06] Snowdrop Short: just append the digit pressed to
the number being displayed
[2009/03/10 14:07] Starky Rubble: right
[2009/03/10 14:07] Snowdrop Short: if you used traditional named
delegates
[2009/03/10 14:07] Snowdrop Short: your code would be swamped with
delegate declartions
[2009/03/10 14:07] Snowdrop Short: so sometimes it is the right tool
[2009/03/10 14:07] Snowdrop Short: and with every thing else
[2009/03/10 14:07] Starky Rubble: I see
[2009/03/10 14:08] Snowdrop Short: you should use the best tool for
the job
[2009/03/10 14:08] Snowdrop Short: and only experience will teach you
the best tools
[2009/03/10 14:08] Snowdrop Short: I can only give some pointers
[2009/03/10 14:08] Starky Rubble: the more powerful the tool, the
more damage it can do lol
[2009/03/10 14:09] Starky Rubble: or work
[2009/03/10 14:09] Snowdrop Short: very true
[2009/03/10 14:09] Snowdrop Short: so .. that is one part
[2009/03/10 14:09] Snowdrop Short: when talking about events
[2009/03/10 14:09] Snowdrop Short: the delegates
[2009/03/10 14:10] Snowdrop Short: which gets executed based on an
event
[2009/03/10 14:10] Snowdrop Short: M1sha actually had an event in her
code the last time
[2009/03/10 14:10] Starky Rubble: right
[2009/03/10 14:10] M1sha Dallin: yep - took me ages to get it to
work :-)
[2009/03/10 14:11] Snowdrop Short: delegates are one part of events
[2009/03/10 14:11] Snowdrop Short: the other part is a hidden part
[2009/03/10 14:11] Snowdrop Short: which the compiler creates behind
the scenes
[2009/03/10 14:11] Snowdrop Short: what happens is that when you
declare an event
[2009/03/10 14:12] Snowdrop Short: is that the compiler goes and
creates some plumbing
[2009/03/10 14:12] Snowdrop Short: to help implement the event
[2009/03/10 14:12] Snowdrop Short: you can override it if you want to
[2009/03/10 14:12] Snowdrop Short: but there is rarely any reason to
do so
[2009/03/10 14:13] Snowdrop Short: the plumbing is really a
collection
[2009/03/10 14:13] Snowdrop Short: because when you trigger an event
[2009/03/10 14:13] Snowdrop Short: several delegates may be invoked
[2009/03/10 14:13] Snowdrop Short: because more that one can be
"listening" for an eventh
[2009/03/10 14:13] Starky Rubble: sure
[2009/03/10 14:14] Snowdrop Short: so the compiler goes a builds a
hidden collection of delegates
[2009/03/10 14:14] Snowdrop Short: the first thing to decide when
dealing with events
[2009/03/10 14:14] Snowdrop Short: is deciding what kind of
information gets sent along with the event
[2009/03/10 14:15] Snowdrop Short: lets say we wanted to create an
event on the group
[2009/03/10 14:15] Snowdrop Short: which was triggered when a new
person got added
[2009/03/10 14:16] Snowdrop Short: we might want to let the event
send the name of the person added
[2009/03/10 14:17] Snowdrop Short: so we'd need to create a delegate
looking something like this
[2009/03/10 14:17] Snowdrop Short: delegate NewPersonInfo(string
name)
[2009/03/10 14:18] Snowdrop Short: in order for everybody to be able
to access it
[2009/03/10 14:18] Snowdrop Short: we give it public visibility
[2009/03/10 14:18] Snowdrop Short: public delegate void NewPersonInfo
(string name);
[2009/03/10 14:19] Starky Rubble: ok
[2009/03/10 14:19] Snowdrop Short: or maybe just "PersonInfo"
[2009/03/10 14:19] Snowdrop Short: that way we might be able to re-
use it
[2009/03/10 14:19] Starky Rubble: right
[2009/03/10 14:20] Snowdrop Short: next.. we need to declare an event
[2009/03/10 14:20] Snowdrop Short: public event PersonInfo
OnNewPerson;
[2009/03/10 14:20] Snowdrop Short: public .. everybody can see and
use it
[2009/03/10 14:20] Snowdrop Short: event
[2009/03/10 14:21] Snowdrop Short: in order to listen in on the
event, you need to register a delegate
[2009/03/10 14:21] Snowdrop Short: which matches the signature of
"PersonInfo"
[2009/03/10 14:21] Snowdrop Short: and the actual name of the event
is OnNewPerson
[2009/03/10 14:21] Snowdrop Short: there are some conventions
[2009/03/10 14:21] Snowdrop Short: for naming
[2009/03/10 14:22] Snowdrop Short: one of which I have violated in my
example
[2009/03/10 14:22] Snowdrop Short: the name of an event usually
begins with "On..."
[2009/03/10 14:22] Snowdrop Short: OnSomeEvent
[2009/03/10 14:22] Snowdrop Short: and the delegate declaration
usually ends on "Callback"
[2009/03/10 14:23] Snowdrop Short: of if I wanted to be conformant
with the conventions
[2009/03/10 14:23] Snowdrop Short: it should have been named
PersonInfoCallback
[2009/03/10 14:23] Starky Rubble: ok
[2009/03/10 14:24] Snowdrop Short: with those declarations made, the
compiler has enough information to create all the plumbing
[2009/03/10 14:24] Snowdrop Short: now .. lets create a delegate for
receiving the event
[2009/03/10 14:25] Snowdrop Short: we know what the signature is
supposed to be
[2009/03/10 14:25] Snowdrop Short: and lets make it a class delegate
[2009/03/10 14:25] Snowdrop Short: in order not to clutter up the
code inside "Main"
[2009/03/10 14:27] Snowdrop Short: here is what I have so far
[2009/03/10 14:28] Snowdrop Short: http://www.pastebin.ca/1357735
[2009/03/10 14:28] Snowdrop Short: let me know when you have it
[2009/03/10 14:28] Adelle Fitzgerald: kk
[2009/03/10 14:28] M1sha Dallin: yep
[2009/03/10 14:29] Snowdrop Short: the only real surprise ....
[2009/03/10 14:29] Snowdrop Short: is in lines 95
[2009/03/10 14:29] Snowdrop Short: and 105
[2009/03/10 14:29] Snowdrop Short: the +=
[2009/03/10 14:30] Snowdrop Short: is just shorthand notation for
adding our delegate to the collection behind the OnNewPerson event
[2009/03/10 14:30] M1sha Dallin: old c syntax
[2009/03/10 14:30] Snowdrop Short: and -=
[2009/03/10 14:30] Snowdrop Short: removes the delegate from the
collection
[2009/03/10 14:30] Starky Rubble: sure
[2009/03/10 14:31] Snowdrop Short: this is the way, delegates are
added and removed from the event collection
[2009/03/10 14:31] Snowdrop Short: other than that.. I hope there are
few surprised
[2009/03/10 14:32] Snowdrop Short: compared to what we have already
talked about
[2009/03/10 14:32] Snowdrop Short: what do you think?
[2009/03/10 14:32] Starky Rubble: it seems to follow
[2009/03/10 14:32] M1sha Dallin: looks ok
[2009/03/10 14:33] M1sha Dallin: but event not yet triggered - at
least I can't spot it
[2009/03/10 14:33] Starky Rubble: It compiles and runs :)
[2009/03/10 14:33] Snowdrop Short: not yet
[2009/03/10 14:33] Starky Rubble: no
[2009/03/10 14:33] Snowdrop Short: because we haven't talked that
part over yet :-)
[2009/03/10 14:34] M1sha Dallin: :-) oops sorry
[2009/03/10 14:34] Starky Rubble: and not today I hope
[2009/03/10 14:34] Snowdrop Short: and that's another piece of
plubling which c# gives you for free
[2009/03/10 14:34] Snowdrop Short: you treat it just like a method
call
[2009/03/10 14:34] Snowdrop Short: and the compiler/runtime will do
everything else
[2009/03/10 14:34] Starky Rubble: ok
[2009/03/10 14:35] Starky Rubble: Hello AQlain this is a c# class -
as you mustve figured out
[2009/03/10 14:36] alain beck: hello!
[2009/03/10 14:36] Snowdrop Short: hiya Alain
[2009/03/10 14:37] Snowdrop Short: http://www.pastebin.ca/1357744
[2009/03/10 14:37] Starky Rubble: There are logs at
http://groups.google.ca/group/osg-community-college?hl=en this is
class 5 of the programmers class
[2009/03/10 14:37] Snowdrop Short: that's it
[2009/03/10 14:37] Snowdrop Short: we have it all now
[2009/03/10 14:37] Snowdrop Short: I think
[2009/03/10 14:37] Snowdrop Short: let me know when you have the code
[2009/03/10 14:38] Adelle Fitzgerald: got it
[2009/03/10 14:38] Starky Rubble: got it
[2009/03/10 14:38] M1sha Dallin: yep
[2009/03/10 14:38] Snowdrop Short: ok
[2009/03/10 14:39] Snowdrop Short: up
[2009/03/10 14:39] Snowdrop Short: ups
[2009/03/10 14:39] Snowdrop Short: I gave you the wrong code
[2009/03/10 14:39] M1sha Dallin: :-)
[2009/03/10 14:39] Snowdrop Short: http://www.pastebin.ca/1357747
[2009/03/10 14:40] Snowdrop Short: that's the one you need
[2009/03/10 14:40] Snowdrop Short: I have added a small person class
[2009/03/10 14:40] Adelle Fitzgerald: umm, which part, top or bottom?
[2009/03/10 14:40] Snowdrop Short: with a small twist to it
[2009/03/10 14:40] Snowdrop Short: the person class is in lines 32-44
[2009/03/10 14:40] Snowdrop Short: but nothing fancy, besides my
small twist
[2009/03/10 14:41] Snowdrop Short: then I have added a method in
Group
[2009/03/10 14:41] Snowdrop Short: in lines 61-66
[2009/03/10 14:41] Snowdrop Short: line 65 if what it is all really
about
[2009/03/10 14:41] Snowdrop Short: "OnNewPerson(p.Name);
[2009/03/10 14:42] Snowdrop Short: that small piece of code will
invoke all the delegates registered to listen in on this event
[2009/03/10 14:43] Snowdrop Short: so you see
[2009/03/10 14:43] Snowdrop Short: the complicated thing behind
events in C#
[2009/03/10 14:43] Snowdrop Short: is really the delegates
[2009/03/10 14:43] Snowdrop Short: the actual event code isn't nearly
as complex as understanding the delegates
[2009/03/10 14:43] Starky Rubble: ok
[2009/03/10 14:44] Starky Rubble: right
[2009/03/10 14:45] Starky Rubble: this reqiures some longer thought
lol
[2009/03/10 14:45] Snowdrop Short: as I said
[2009/03/10 14:45] Starky Rubble: it makes sense and all
[2009/03/10 14:45] Snowdrop Short: delegates are more than "function
pointers"
[2009/03/10 14:46] Starky Rubble: but my goodness
[2009/03/10 14:46] Starky Rubble: right
[2009/03/10 14:46] Snowdrop Short: and there is even more
[2009/03/10 14:46] Snowdrop Short: but lets wait on that
[2009/03/10 14:46] Starky Rubble: arggh (starky needs a break)
[2009/03/10 14:46] M1sha Dallin: good plan - think I'm full
[2009/03/10 14:47] Adelle Fitzgerald: me too
[2009/03/10 14:47] Snowdrop Short nods
[2009/03/10 14:47] M1sha Dallin: my head hurts again :-)
[2009/03/10 14:47] Snowdrop Short: delegates
[2009/03/10 14:47] Adelle Fitzgerald: <-- needs some ;)
[2009/03/10 14:47] Snowdrop Short: are a big topic
[2009/03/10 14:47] Starky Rubble: I just need to leave the room for a
minute lol
[2009/03/10 14:47] Starky Rubble: brb
[2009/03/10 14:47] Snowdrop Short: I think we should call it a day
[2009/03/10 14:48] Snowdrop Short: but now, we have the tools to
disect the code which M1sha presented last tuesday
[2009/03/10 14:48] M1sha Dallin: Thursday
[2009/03/10 14:48] Snowdrop Short: sorry
[2009/03/10 14:48] M1sha Dallin: I think
[2009/03/10 14:48] Snowdrop Short: Thursday
[2009/03/10 14:48] Snowdrop Short: you are right
[2009/03/10 14:49] Snowdrop Short: one of the reasons why there is so
much more to delegates
[2009/03/10 14:49] Snowdrop Short: is that you often find yourself on
the receiving end of an event
[2009/03/10 14:49] Snowdrop Short: so you need a lot of flexibility
in how you received them
[2009/03/10 14:50] Snowdrop Short: but it isn't that often that you
write code which sends events
[2009/03/10 14:50] Snowdrop Short: it happens ofcourse, but receiving
events is more common
[2009/03/10 14:50] Adelle Fitzgerald nods
[2009/03/10 14:51] Starky Rubble: Ok Im back
[2009/03/10 14:51] Snowdrop Short: if you look at the methods
available on a List
[2009/03/10 14:52] Snowdrop Short: you'll discover that it has a
method called
[2009/03/10 14:52] Snowdrop Short: "ForEach"
[2009/03/10 14:52] Starky Rubble: right
[2009/03/10 14:52] Snowdrop Short: and that "ForEach" actually takes
a delegate as a parameter
[2009/03/10 14:52] Adelle Fitzgerald: gotcha
[2009/03/10 14:53] Snowdrop Short: delegates are used a lot of places
[2009/03/10 14:53] Snowdrop Short: later on
[2009/03/10 14:53] Snowdrop Short: we'll look into a whole section of
the language
[2009/03/10 14:54] Snowdrop Short: designed explicitly for working on
collections and applying delegates on those collections
[2009/03/10 14:54] Snowdrop Short: but that's going to be delegates
202
[2009/03/10 14:54] M1sha Dallin: :-)
[2009/03/10 14:54] Snowdrop Short: maybe 303
[2009/03/10 14:54] Snowdrop Short: since that part wasn't in the
language until version 3
[2009/03/10 14:55] Starky Rubble: yes - I've avoided looking at that
stuff so far lol
[2009/03/10 14:55] M1sha Dallin: A quick question - Mono uses C#
Version 3 and .Net Framework Version 2 ?
[2009/03/10 14:56] Snowdrop Short: yes.. more or less
[2009/03/10 14:56] Snowdrop Short: but some parts of the framework is
3
[2009/03/10 14:56] M1sha Dallin: ok - just wanted to know what I
could use (or not)
[2009/03/10 14:57] Snowdrop Short: the more recent versions of mono
supports the full version 3 syntax
[2009/03/10 14:57] Snowdrop Short: but execpt for a few places, the
framework is version 2
[2009/03/10 14:57] M1sha Dallin: but Opensim is built with .Net 2?
[2009/03/10 14:57] Snowdrop Short: yes
[2009/03/10 14:57] M1sha Dallin: ok - ty
[2009/03/10 14:58] Snowdrop Short: until more linux distributions has
the latest versions of Mono
[2009/03/10 14:59] Snowdrop Short: one of the bigger distributions
"Ubuntu" is sill a bit behind on updating to the more recent versions
of Mono
[2009/03/10 14:59] Snowdrop Short: ok
[2009/03/10 14:59] Snowdrop Short: I think we deserve a break now
[2009/03/10 14:59] Snowdrop Short: we've covered a lot of ground
[2009/03/10 14:59] Snowdrop Short: and thought some pretty new
thoughts
[2009/03/10 14:59] Snowdrop Short: like using code in the same way we
use other variables
[2009/03/10 15:00] Adelle Fitzgerald nods
[2009/03/10 15:00] Starky Rubble: tis true
[2009/03/10 15:00] Snowdrop Short: can calling back into already
running methods
[2009/03/10 15:00] Snowdrop Short: and calling back, even
[2009/03/10 15:01] Snowdrop Short: so ... lets see what kind of
trouble we can stirr up next tuesday :-)
[2009/03/10 15:01] M1sha Dallin: :-)
[2009/03/10 15:01] Snowdrop Short: I think we should try to do
visibilty and encapsulation 102
[2009/03/10 15:02] Starky Rubble: There are some ArrayLists wearing
"Kick ME!" signs
[2009/03/10 15:02] Starky Rubble: ok
[2009/03/10 15:02] Snowdrop Short: I agree very much
[2009/03/10 15:02] Snowdrop Short: maybe we should do something on
generics as well
[2009/03/10 15:02] Starky Rubble: cool
[2009/03/10 15:02] Snowdrop Short: ok
[2009/03/10 15:02] Snowdrop Short: time for bed
[2009/03/10 15:02] M1sha Dallin: yep
[2009/03/10 15:02] Snowdrop Short: but as usual
[2009/03/10 15:03] M1sha Dallin: ty Snowdrop
[2009/03/10 15:03] Snowdrop Short: if you need me, I'm on IRC
[2009/03/10 15:03] Starky Rubble: bye now
[2009/03/10 15:03] Starky Rubble: and thanks again
[2009/03/10 15:03] Snowdrop Short: thank you for listening to me
babbling
[2009/03/10 15:03] Adelle Fitzgerald: goodnight Snowdrop, thanks :)
[2009/03/10 15:03] Snowdrop Short: nite
[2009/03/10 15:03] M1sha Dallin: g'night




http://www.pastebin.ca/1357624

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate string AdditionalInfo();
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message());
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
static string Bubble()
{
return "bubble";
}

public static void Main(string[] args)
{
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(new Group.AdditionalInfo(Bubble));
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
}
}
}




http://www.pastebin.ca/1357657

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
static string Bubble(int n)
{
return " Bubble(" +n +")";
}

public static void Main(string[] args)
{
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(new Group.AdditionalInfo(Bubble));
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
}
}
}




http://www.pastebin.ca/1357672

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")";
};
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(bubble);
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
}
}
}




http://www.pastebin.ca/1357682

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")";
};

Group.AdditionalInfo b2;

b2 = bubble;
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(b2);
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
}
}
}




http://www.pastebin.ca/1357696

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
int m = 7;
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
};

Group.AdditionalInfo b2;

b2 = bubble;
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(b2);
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
}
}
}




http://www.pastebin.ca/1357709

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
int m = 7;
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
};

Group.AdditionalInfo b2;

b2 = bubble;
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
});
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
}
}
}




http://www.pastebin.ca/1357735

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate void PersonInfo(string name);
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public event PersonInfo OnNewPerson;

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
static void OnNewPerson(string name)
{
Console.WriteLine("New person added:" + name);
}

public static void Main(string[] args)
{
int m = 7;
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
};

Group.AdditionalInfo b2;

b2 = bubble;
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
g.OnNewPerson += OnNewPerson;
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
});
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
g.OnNewPerson -= OnNewPerson;
}
}
}




http://www.pastebin.ca/1357744

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}


public class Group : GroupBase
{
public delegate void PersonInfo(string name);
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public event PersonInfo OnNewPerson;

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
static void OnNewPerson(string name)
{
Console.WriteLine("New person added:" + name);
}

public static void Main(string[] args)
{
int m = 7;
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
};

Group.AdditionalInfo b2;

b2 = bubble;
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
g.OnNewPerson += OnNewPerson;
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
});
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
g.OnNewPerson -= OnNewPerson;
}
}
}




http://www.pastebin.ca/1357747

using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Person
{
string _Name;
Guid _ID;

public string Name { get { return _Name; } }

public Person(string name, Guid id)
{
_Name = name;
_ID = id;
}
}

public class Group : GroupBase
{
public delegate void PersonInfo(string name);
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public event PersonInfo OnNewPerson;

public void
AddPerson(Person p)
{
_Members.Add(p);
OnNewPerson(p.Name);
}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
static void OnNewPerson(string name)
{
Console.WriteLine("New person added:" + name);
}

public static void Main(string[] args)
{
int m = 7;
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
};

Group.AdditionalInfo b2;

b2 = bubble;
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
g.OnNewPerson += OnNewPerson;
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
});
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
g.OnNewPerson -= OnNewPerson;
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;

namespace Groups
{
public class GroupBase
{

public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Person
{
string _Name;
Guid _ID;

public string Name { get { return _Name; } }

public Person(string name, Guid id)
{
_Name = name;
_ID = id;
}
}

public class Group : GroupBase
{
public delegate void PersonInfo(string name);
public delegate string AdditionalInfo(int n);
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public event PersonInfo OnNewPerson;

public void
AddPerson(Person p)
{
_Members.Add(p);
OnNewPerson(p.Name);
}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public void WriteToConsole(AdditionalInfo message)
{
base.WriteToConsole();
Console.WriteLine(ToString() + message(5));
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
static void OnNewPerson(string name)
{
Console.WriteLine("New person added:" + name);
}

public static void Main(string[] args)
{
int m = 7;
Group.AdditionalInfo bubble = delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
};

Group.AdditionalInfo b2;

b2 = bubble;
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
g.OnNewPerson += OnNewPerson;
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole(delegate(int n)
{
return " Bubble(" +n +")[" + m + "]";
});
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
g.OnNewPerson -= OnNewPerson;
}
}
}




Reply all
Reply to author
Forward
0 new messages