How it works...

Let's have a look at what we have achieved so far. From steps 1 to 4, we opened Visual Studio 2017 and created a blank solution. Blank solutions are a very good foundation for a project that has multiple projects. In steps 5 to 10, we added a new project to the blank solution. In step 7, we used an existing base .NET Standard 2.0 project template and gave it a proper name in step 8. 

In steps 11 and 12, we changed the default Class1.cs to a meaningful name. These names are very important and it helps a developer to understand what the code is for inside that file. In this case, we chose Chapter2.Primitives.PrimitiveLib as the project name. The first two sections provide the solution name and, at the end, there is the actual project name. 

In step 14, we created code that includes a public method. The method takes an int type variable as the parameter. int is a primitive data type that is supported in the framework itself, so we have used it inside a .NET Standard library. It means the code can be shared across .NET Framework, .NET Core, and Mono running applications. 

The data type int is an alias for System.Int32 and these are the primitive types supported under .NET that can be used and shared in a .NET Standard 2.0 library: 

  • Boolean
  • Byte
  • SByte
  • Int16
  • UInt16
  • Int32
  • UInt32
  • Int64
  • UInt64
  • IntPtr
  • UIntPtr
  • Char
  • Double
  • Single

The code takes a char variable and each if statement validates the marks sent through the yourMarks parameter in the method. Finally, the method returns a char value as the grade and then we confirmed all the syntax was correct and built successfully in step 15. In step 16, we created another method that converts centimeters to inches. The input parameter is another primitive type called double, which is also an alias for System.Double. This is because C# represents all primitives as objects. Inside the code, one variable already converts centimeters into inches and is stored as oneCmToInchesIn the last line, we return the inches as double, converted from centimeters given in the parameter of the method. 

In step 17, we did another build to check all code for syntax and finally did a save all.