Recently I’ve joined a book club which I found on the social media (PTT), this book club was hold every Sunday. After I’ve joined the book club, I learned lots of new techniques that I used to ignore or I never knew; therefore, I would like to share what I’ve learned from there. The things that I am going to share are some techniques that I’d never notice, so I won’t explain everything from the beginning. And for those that think these techniques are too easy and was written on the book, please forgive me for my ignorance because I wrote this in order to remind myself of some key points.
C# is the first programming language that I learned. Actually, in the first semester of my college I used to have learned C and C++; however, I failed the class due to my lack of concentration in class. In the second semester, I decided to learn programming language seriously. At that time, there is a course call Windows Programming and the course is all about C#. During the class, I designed a tower defense game by using C# only. It was a special memory for me and I think there are lots of things that I can improve in order to make the game better. (If I have the time to redo it again lol)
The main purpose that I joined the book club is to study more about programming. Also, most of the member of the book club are non-student. I can learn some techniques of cooperate development, how to improve efficacy and know what’s going on in industry. The book club was divided into two groups, one group study advanced C# and the other study ASP.NET MVC. These two groups will assign weekly homework and on every Sunday both groups will come up with a person that’s going to share some key points and techniques that is important in the homework. I’ll explain what’s MVC in my next review, when I have a full understand of it.
This week’s book club we were talking about Type declaration, basically I have had some understand about basic types, such as int, float, string etc. And most of them are all about the “string”.
Some people might need to store a path of a file in to a string while they are using C#; however, we can’t use ‘\’in a string because it will be seen as an escape character. Escape character are something like “\n” (end line) “\t” (tab). Today we assume that we have a file name “Lion.jpg” in a file name “Willake” in local disk-D, and we want to store its path in to a string. Then, we declare the string like this:
string path = "D:\Willake\Lion.jpg";
The compiler will tell you that there is an error, so we have to declare it like this:
string path = "D:\\Willake\\Lion.jpg";
Its quite bother to add an extra ‘\’ to every ‘\’, but actually we just need to add a ‘@’ in front of the quotation mark and it will be fine. Though you still have to write it in the other way if you really need to use “\n”.
string path = @"D:\Willake\Lion.jpg";
We usually face the problem of concatenating multiple strings while we using C#, and what we do is adding a ‘+’ between strings.
string msg = "Hello,",Name = "Peter";
When we use that method, you may think it will be like this in the memory:
Stored the data in the original location of the string. Actually, it will be like this:
Every time we use ‘+’ to concatenating strings, the memory will assign a new space to store the string. The original string won’t be deleted and will become a trash. It is because CLR wants to save the memory space so it build a hash table system in heap. Relative to string, StringBuilder class is better. It is changeable so it won’t assign any new space. we can use it to concatenate strings.
string name = "Peter";
We used to use String.Format() function to converts the value of objects to strings and inserts them into another.
string firstName = "Willake";
In C# 6.0, Microsoft add a new feature called “Interpolated Strings”. You can add a ‘$’ before the string.
string firstName = "Willake";
Both of results will display “Willake Lin ‘s salary is NT$80000 per month.”. If there are lots of variables that need to be insert into a string, using string.format() isnt that convenient because you need to compare against each other and that is a huge task.
This is what I learned from the study group on June 5. Everyone in the group is nice, they won’t alienate people who is just a beginner. I’m really looking forward to next gathering, hoping i can learn more interesting things.