by Joel Limardo
Home | Twitter | LinkedIn | Consulting | About | RSS | Map
Areas:
Process
 
Technical
 
Projects:


Tue, 10 Jan 2017

.NET Projects

  1. Read ILSpy - Assembly Browser/Decompiler(Windows)
  2. Initial Mono vs. CSharp Shell
  3. Simple Casting
  4. While Loop
  5. For Loop
  6. Switch
  7. Arrays
  8. Objects
  9. Namespaces
  10. Static Methods
  11. Numeric Input
  12. MonoDevelop
  13. Passing Arguments
  14. Variable Arguments
  15. DateTime
  16. Inheritance
  17. Nullable Types
  18. Anonymous Types


posted at: 22:47 | path: /technical/programming/DOTNET | this entry | top

Nullable Types

csharp> int? m = null;
csharp> int p = null;
(1,10): error CS0037: Cannot convert null to 'int' because it is a value type
csharp> int y = m?? - 1;
csharp> y
-1

Strange syntax for nullable types (question mark) and even stranger when you try to use them (double quotes).



posted at: 22:43 | path: /technical/programming/DOTNET | this entry | top

Anonymous Types

csharp> var v = new {Amount=100 , Message="hi"};
csharp> v.Amount;
100
csharp> v.Message; 
"hi"
csharp> v.Amount = 999;
(1,4): error CS0200: Property or indexer `anonymous type.Amount' cannot be assigned to (it is read-only)

So anonymous types are useful for holding a bunch of read-only values together.



posted at: 15:18 | path: /technical/programming/DOTNET | this entry | top

Initial Mono vs. CSharp Shell

With the Mono kit there is a 'Mono shell' that can be run from the command line like this:

 csharp

It produces some output like this:

 csharp> string sFahr = "88";
 csharp> print ((Int32.Parse(sFahr) - 32) * (5.0/9.0)); 
 31.1111111111111
 csharp> print ((Int32.Parse(sFahr) - 32) * (5/9));     
 0
 csharp> print ((Int32.Parse(sFahr) - 32) * (5.0/9.0));
 31.1111111111111

It works with standard C#:

using System;
 class celsius 
 { public static int Main(string[] args){
      Console.Write("Enter temp in degrees Farenheit:");
      string sFahr = Console.ReadLine();
      double dFahr  = double.Parse(sFahr);
      double dCelsius;
      //dCelsius = (dFahr - 32.0) * (5.0 / 9.0) ;
      dCelsius = (dFahr - 32.0) * (5/9) ; 
      Console.WriteLine("Temperature in degrees Celsius = " + dCelsius );
      return(0);
 }
 }

Because it works the same way you can try out syntax and run all sorts of tests with it. There's even a way to run it in standalone scripts (see the manpage).

Update #1: You have to give sFahr (variable above) a type or csharp will issue an error.



posted at: 15:04 | path: /technical/programming/DOTNET | this entry | top

© 2015-2017. All Rights Reserved. All original code appearing on this site is MIT Licensed unless otherwise noted.