Monday, 29 October 2018

IndexOf keyword in .NET

IndexOf is an extension method (default functionality can be overridden) on string.
Method will return index number of a character position in string.

Take a look in this example

public static void Main()
 {
  var character = "ABS";
  Console.WriteLine(character.IndexOf("B"));
 }

We are expecting to see 1 in Console.

If character does not exist in the string method will return -1.


public static void Main()
 {
  var character = "ABS";
  Console.WriteLine(character.IndexOf("F"));
 }

Above method will return -1.


Tuesday, 16 October 2018

Understanding versioning in npm and bower

If you ever got confused what is the difference between 1.1.2 and 1.1.x, or ^1.1.2 and ~1.1.2 numbers next to your npm package name keep reading this post.

When you have for instance "angular": "~1.6.1" defined in your package.json and version 1.6.2 is available on the server it will pull this version, however if version 1.7.1 is available it will ignore it.

In order to pull 1.7.1 you can change ~ to ^ so "angular": "^1.6.1"
For major update it is recommended to manually update version as major version usually means breaking changes.

~ - patch update
^ - minor update

You can find all available packages and version https://semver.npmjs.com/