C# Sharpen Your Sword

Do you know C#? Yes. I do. How long have you been using it? 4-5 years. I am an experienced C# developer, sir.

While interviewing candidates for C# developer position, I came across many CV with saying kind of the same thing. Candidates claim that they are experienced C# developers. I am sure they are. Many of them are. But, unfortunately, there are some who misunderstood themselves.

Why was that? Regardless of C# evolution, they kept writing the same code as if it was C# 1.0. Many just use C# to write basic code such as class, if statement. They use basic data types not even care or know that there are better versions of data structures that can do a better job.

Many experienced developers have problems with writing code that access database, manipulate XML, read files, … The forever argument is they will google when they need it. Ok, that makes sense. Oh no! experienced developers ask google for basic operations?? Hmm that does not make any sense at all.

One day I realized that I am a C# developer, too (Just kidding I know I am a C# developer, writing C# code for a living). I started to ask myself

How much do I know about C#?

I know some. That’s all I can admit. With the thinking flow, I thought many C# developers have that problem; they are not aware of how much they know about C#.

I decided to compose a list of fundamental that every developer should know about C#. Not everyone uses all of them in their daily job.

There are 2 purposes when I composed the list

  1. Self-improvement: I want to improve my C# skill regardless of where I am now. I want to have a strong foundation.
  2. Help others: I have developers at my workplace. I want to help whoever accept my help. Remember that helping is growing, a perfect win-win situation.

 

Primitive Data Types and Keywords

What are differences between integer and float data types? between float and double? And when to use what?

The problem: many do not think twice before deciding a data type to use. What primitive data type do you use to hold a person’s age? Probably it is int, right?

What are checked and unchecked keywords used for?

String Manipulation and Regular Expression

Developers deal with string more often than they thought.

  1. Concatenate strings
  2. Format string with Join
  3. Format string with Format
  4. Find string with regular expression
  5. ToString(): when displaying a value (integer, date, currency, …), we convert it to a string.
  6. String and Culture

The regular expression is an exciting, sometimes headache, topic. How many ways are there to check if a string is an integer?

Protection Levels

Hey, do you remember these: Private, Protected, Internal, Protected Internal, and Public?

The problem: Do not know how to take advantages of the language to protect data correctly.

I have seen developers have a habit of using public for methods and properties, private for fields. The public modifier is used because it is the easiest, which allows a function can be consumed everywhere.

When was the last time you think of using Internal, or Protected Internal?

Collections and Concurrent Collections

How many types of collection do you know? And when to use what? List, Queue, Stack, Dictionary, Array, ArrayList, … Oh how about the readonly and concurrent versions?

The problem: Not use the right collection. Usually, developers take the easiest one instead of a proper one.

Using the right collection is very important. Because it will protect the data from unexpected access, unexpected modification.

The most common use is the List<T> class. Because it does not require any thinking process.

To use a proper collection type, at least a developer should consider these questions

  • Is it ordered?
  • Access pattern? FIFO, FILO, Random, by index, by key, …
  • Is it readonly?
  • Do we need to keep it after processing all items?
  • What are the most common operations (business operations) on that collection?

 

Threading, Task, Parallelism, Async and Await

This topic is not easy at all. It is not required that every developer has a deep understanding; however, a fundamental is crucial.

The problem: Use without a bit of understanding how it works. This causes many nasty issues in production.

XML

Sometimes, we forget how to process an XML document. That’s sad. A direct XML processing might not be popular these days. But a proper understanding is important.

File and I/O

The problem: We do not know what we are doing.

When there is a need to read a file, developers use the first API available File.Open with just enough required parameters. Many times, they fail to ask

  1. What is the file encoding?
  2. What if a file is being opened by another process?
  3. What if a file does not exist?
  4. What if a file is too big?
  5. Do we need to load its content at once? or should we process line by line?

Have you ever wondered those questions?

ADO.NET

The rise of ORM tools (EF, NHibernate, …) makes developers’ life easier when dealing with databases. That comes at a cost. Developers seem to forget how to interact with databases.

The problem: Do not know how to work with databases.

When doing interviews, I asked candidates about the SQL transaction in an EF application. They said EF does it all for us. Yes. It does. The next question, when does it commit a transaction? Answer: Oh, EF does it for us. Period.

Lacking the database fundamental is such a bad excuse.

LINQ

It is hard to say whether it is a fundamental thing. It came out with C# 3.0. Before, you can write code with for loop. Proper use of LINQ will improve the readability of your code.

Covariance and Contravariance

Same as LINQ. If you understand them, you are rock.

Dynamic

Not used often, but listed here for reference.

 

Having the list is a first step to sharpen my C# sword. The list works as an agenda, a guiding star. Some of the items I am good at, others I am a beginner.

Stay calm, sit down, put hands on the sword, move it slowly. That’s good! Let’s the game on.