Wednesday, February 24, 2016

cSharpDictionary.ContainsKey("GoFish") - Another section of chapter 8

I still am not done reading Chapter 8. Although I have been reading and coding most nights (except the nights my wife and daughter were both sick or doing my taxes which are always phone *please insert sarcasm*) it takes me a while to get through the material. 

Well, since my last post a week and a half ago, I have mostly been working on a project in chapter 8. I tried really hard not to use the help for this project and perhaps I have learned something during the week. I just finished the Go Fish project in chapter eight and I did use the code that is provided in the book. I was stuck, what was I to do? Sometimes I ask myself, is object oriented programming for me? I felt when doing VBA that I got a relatively good grasp on what I was doing and didn't have to refer to the web much after doing it for a while. Perhaps I will start feeling that way with C#. I will say there are pieces that I look at what needs to be done and a light bulb goes on. Those are the days that help me continue spending any small amount of free time I have trying to become a coder. Just code more each day I guess (I try to do CodeWars but feel sometimes they are above what I know, maybe those are the good ones to actually test my skills) and have joined some communities like codenewbie.org (full of people wanting to learn to code from all backgrounds). What helped you learn to code?

One great thing about this chapter is that it made me really look at overloaded objects. As usual, We have talked about overloading before at work and I have never really grasped what that meant. This chapter was discussing overloaded methods and I probably missed it early on in the book, but I was really feeling lost. I spent some time investigating to find out that I really didn't know much about overloaded objects. Come to find out, they can probably come in handy. I like the definition from MSDN:

Members can have the same name as long as their parameter lists differ. When two or more members in a type are the same kind of member (method, property, constructor, and so on) and have the same name and different parameter lists, the member is said to be overloaded.



Just pass the correct parameters and the code will use the correct overloaded object. The Go Fish project actually uses one so you can find what card the computer will choose and then call the method that the human player uses. pretty nifty.

Hey, you can also create a dictionary to store definitions of keys. Just do:
Dictionary kv = new Dictionary ;

You set your TValue object type and key (keys must be unique just like the dictionary you use!) and enter data. You can then count the data, see if objects are in the dictionary, remove items you don't like, and add items you do like. There seems to be a lot more you can do with dictionaries. 

GoFish! Game - I still have not won the computer, I can only tie the computer. AI must cheat.

Until next time.

"I like to fish. Fishing is always a way of relaxing." Tom Felton

No comments: