Comparing using CompareTo C# Method

 

A colleague asked me for a suggestion on the program module he is doing that involves determining if one value is “>” greater than, “=” equal or “<” less than another value. I first thought of a solution involving a stack but its too low level and involves much longer code. After some suggestions and trying to think of another way, he came across of a solution to use CompareTo C# method.

What is CompareTo C# Method?

First, MSDN defines IComparable as an interface that “Defines a generalized type-specific comparison method that a value type or class implements to order or sort its instances.” It has a method called CompareTo which as defined by MSDN “Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.”

The CompareTo method is available on all objects as long as the objects has the same type. See the sample code below for comparing value types integer and a string type.

CsharpCompareTo

 

The Return Value of CompareTo

The CompareTo method has a return value of int. The integer value return will be one of the values less than 0, 0 or greater than zero as what is shown below.

CompareToReturnValues

 

Nullable Types Does Not Implement CompareTo

Take note that Nullable types like int? short for Nullable<int> does not implement the CompareTo method. It will not even compile since the method is not implemented.

CompareToNullable

This blog post will serve as a quick reference for me whenever there is a need for me to use sorting or comparison of data when programming. I hope it will serve the same for you.

 

 

Changing My DNS Provider to DNSimple – What DNS Record?

 

Problem with my current DNS provider – GoDaddy.com

I made a blog post two years ago on how I setup this site File -> New Blog Project. As of this writing, this site is using WordPress and GoDaddy.com for web hosting and DNS. Lately, I have noticed that sometimes I cannot access my website noelarlante.com and its admin page. Its maybe my internet provider is slow? or my internet is totally down? A quick access to Google proves otherwise.

I did a trace route to noelarlante.com and to my surprise I got timeouts (* * *) on after a certain ip address. My main hosting ip address is working which means the domain name resolution is not working due to the time out.

Traceroute has started…

traceroute to noelarlante.com (203.124.115.1), 64 hops max, 72 byte packets

 1  192.168.11.1 (192.168.11.1)  1.474 ms  1.515 ms  1.011 ms

 2  192.168.254.254 (192.168.254.254)  1.785 ms  1.685 ms  1.584 ms

 3  180.191.75.1 (180.191.75.1)  17.557 ms  17.863 ms  17.545 ms

 4  10.109.9.65 (10.109.9.65)  17.431 ms  21.192 ms  17.735 ms

 5  120.28.0.193 (120.28.0.193)  18.478 ms  23.496 ms  17.978 ms

 6  120.28.10.93 (120.28.10.93)  18.563 ms  21.173 ms  18.075 ms

 7  120.28.4.94 (120.28.4.94)  49.112 ms  52.709 ms  48.848 ms

 8  203.169.57.37 (203.169.57.37)  48.052 ms  48.126 ms  46.980 ms

 9  xe-5-2-0-xcr1.sgs.cw.net (195.2.10.214)  87.515 ms  86.563 ms  86.042 ms

10  ae0-xcr1.sng.cw.net (195.2.10.149)  77.411 ms  78.375 ms  76.861 ms

11  * * *

12  * * *

13  * * *

14  * * *

15  * * *

16  * * *

17  * * *

18  * * *

19  * * *

20  * * *

 

Although I still have two more years with GoDaddy DNS, but I have decided to try and use DNSimple.

Moving My DNS service to DNSimple

DNSimple Support page provides a topic on How Transfer Domain Without a Downtime,  which is the perfect information I need to prevent downtime for my website. Transferring a domain to DNSimple was painless. Its just that I missed a step that ended my site to be down for a day – more on that next.

DNS  DNSimpleDomainAddTransfer

Steps on transferring a domain without a downtime

Here are the steps on how to transfer a domain to DNSimple without a downtime based from the Support page of DNSimple. I’ve highlighted the one step I’ve missed.

After doing the *ALL* the steps I thought that I will just need to wait for the DNS to propagate to all servers and then thats it, transfer done. But after awhile I tried to hit noelarlante.com but I got a “Host Unreachable” error on my browser. Something is wrong and I soon figured that there is a disconnect from my DNS to my hosting server.

Problem Solved – I Missed Adding DNS Records

According to Wiki – DNS records or resource records (RR) is the basic data element in the domain name system.
There are many record types that you can use. DNSimple support has the information about each of them – http://support.dnsimple.com/categories/dns/

 I only care about A, CNAME

A – An A record is an Address. This is the record that maps the address i.e. noelarlante.com to my hosting site

CNAME – CNAME is short for Canonical Name. It is the record that maps an alias to an address. The “www” is considered an alias or an address going to noelarlante.com. If no CNAME with “www” is added to the DNS record, www.noelarlante.com will not be resolved to noelarlante.com.

DNS  DNSimpleAddAliasRecord

DNS  DNSimpleDNSRecords

I got my website a new DNS service provider and so far I’m happy with the response time when I visit my site. This is not in anyway a paid advertisement for DNSimple, I’m just sharing my experience and hope others can find this post and not forget that DNS record step.

 

Notepad++ – Source Code Editor and More

SyntaxHighlighting.PNG

  Using Notepad++ with Visual Studio To compliment Visual Studio, I use Notepad++ as my other source code editor. Visual Studio is still my primary IDE but its good to have Notepad++ on the side for that quick search in files, syntax … [Continue reading]

LocalDb – SQL Express for Developers

VSSqlExpressConnectoin.PNG

  When you install Visual Studio 2012 or higher the Sql Server Express component is also installed on your machine. When you add a connection to a database within VS I normally use .\SQLEXPRESS as the server name. The .\SQLEXPRESS … [Continue reading]

Chrome Error Could Not Create Download Directory

Chrome-Could-Not-Download-Directory-Error.png

  I was trying to add a Google Chrome extension for my Twitter and got this error Chrome error Could not create download directory. I thought its the same error I encountered using Chrome extension the last time - Google Chrome … [Continue reading]

Visual Studio 2012 Custom Installation Option Missing

Visual-Studio-Installer-Feature-Options.png

  I have installed Visual Studio 2012 several times in the past, its just now that I want do custom installation. Thank you to the limited space of an SSD drive, I need to keep the Visual Studio 2012 installation to a bare minimum. Just … [Continue reading]