Home > Development > C++ Const Methods For C#

C++ Const Methods For C#

As some people may know I have been doing a lot of C++ in my spare time lately. I am looking at some C++ features I wish now were in C#. Obviously this is my own opinion and I know that the C# language is already quite large but I do like the fact that you can mark a method as const in C++.

Well if you do not know what this means do not worry its really easy. It just means that when you call a method marked as const on the object your working with the compiler guarantees that the method will no cause any side effects on the object. i.e. the objects state wont change.

Here is an example of a const method

class Customer{
string getName() const;

This would be useful to know when working in C# also as it means that the developer can be sure that that there are no nasty side effects lurking around. It also support Command Query Separation as query methods do not cause side effects.


Categories: Development Tags: , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: