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


Mon, 31 Aug 2015

Variable Number of Arguments

 namespace Soup {
 //..
    public int addItUp(params int[] Nums)
    {
       int Total = 0;
       foreach (int n in Nums) {
           Total += n;
       }
       return (Total);
    }
 //..
 csharp> string [] s = {};
 csharp> Can c = new Can(s);
 csharp> print (c.addItUp(4,3,2,2));
 11
 csharp> print (c.addItUp(4,3,2,1)); 
 10
 csharp> print (c.addItUp(2,4,6,8,10));


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

Out Arguments

It is weird but when you want to modify an argument you have to declare your intent in the method itself and when you make the call...

 
    public class Can {
     //..
     public void openCan(out string didIt){
         didIt = "yes, I did it";
     //..
    csharp> LoadAssembly("/tmp/Can.dll");
    csharp> using Soup;
    csharp> string [] dummy = {};
    csharp> Can c = new Can(dummy);
    csharp> string initialValue = "something I have";
    csharp> c.openCan(initialValue);
     {interactive}(1,4): error CS1502: The best overloaded method match for Soup.Can.openCan(out string)' has some invalid arguments...Argument#1' is missing `out' modifier
    csharp> c.openCan(out initialValue);
    csharp> print (initialValue);
    yes, I did it


posted at: 21:25 | path: /technical/programming/DOTNET | this entry | top

Passing Arguments

When using a scripting language you can simply pass a reference to an array. In CSharp you have to tell the method that you are intending to pass an array:

 namespace Soup {
    using System;
     public class Can {
         public Can(string []manufacturers) { 
              foreach(string manu in manufacturers) {
                   Console.Write(manu + "\n");
              }
         }
     }
 }
 csharp> LoadAssembly("/tmp/Can.dll");
 csharp> using Soup;
 csharp> string [] manufacturers = {"Progresso","Campbells","Aldi Brand"};
 csharp> Can c = new Can(manufacturers);
 Progresso
 Campbells
 Aldi Brand


posted at: 20:58 | path: /technical/programming/DOTNET | this entry | top

Underserved Markets

It is a good idea to look for markets that are not presently being served but have been subjected to significant (somewhat unexpected) marketing exposure. For instance, consider a company in a neighboring town that advertises regularly on television but has no stores beyond its own borders. Another simple example is a company that fails to perform the periodic 'secret shopper' analysis of its employees and thus does not witness them driving away certain classes of customers due to bias. This opens up the floodgates of opportunity to compete. In fact, probably the single most important factor to study before entering a market would be the geographic and psychological biases of your competition. It is about the closest thing to free money you can get because there are customers with money in hand being turned away.



posted at: 20:40 | path: /technical/business/consulting | this entry | top

Consulting

  1. Underserved Markets
  2. Social Networking
  3. Building a Referral Base


posted at: 20:32 | path: /technical/business/consulting | this entry | top

Numeric Formatting

There is a whole list of things you can do to modify number formats. It is a bit like printf in other languages.

csharp> string p = String.Format("{0} is {1}",24,24); 
csharp> print (p); 
24 is 24
csharp> string p = String.Format("{0:C} is {1}",24,24);
csharp> print (p);
$24.00 is 24
csharp> string p = String.Format("{0:C} is {1:X}",24,24);
csharp> print (p); 
$24.00 is 18 csharp> string p = String.Format("{0:C} is {1:##0.0#}",24,24); csharp> print (p);
$24.00 is 24.0


posted at: 19:26 | path: /technical/programming/DOTNET | this entry | top

Dealing with Numeric Input

The data types make dealing with string input and converting it much more annoying than scripting languages. Getting familiar with the various static methods of core classes helps.

      // Scan through the SSN to prove it has numbers
      public static bool hasNumbersInRightPlaces ( string SSN ) {
           int SSNLength = SSN.Length;
           bool isGood = true;
           for (int i=0; i<= SSNLength - 1; i++) {
                if ((i == 3) || (i == 6)) {continue; }

                if (Char.IsDigit(SSN[i]) == false)
                {
                     isGood = false;
                }
           }
           return (isGood);
      }


csharp> LoadAssembly("./Student.dll");
csharp> using AnExample;
csharp> Student s = new Student("11a-aa-1111");
csharp> Describe (s);
"public class Student {
...
csharp> Student.hasNumbersInRightPlaces(s.SSN);
false
csharp> Student s = new Student("111-11-1111"); 
csharp> Student.hasNumbersInRightPlaces(s.SSN); true


posted at: 19:25 | path: /technical/programming/DOTNET | this entry | top

MonoDevelop

It is annoying but there doesn't appear to be a ILSpy in the Mono kit I'm using. I'm using:

 Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-8)

Perhaps this is old. At any rate, in order to view inside of assemblies you can use MonoDevelop, expand to see the References folder in the left-hand side treeview, and right click. Choose Edit References, click on the .Net Assembly tab and search around for your assembly. Use the Add button at the bottom to add it to the current project. After this you can use the View->Assembly Browser to view the assembly innards.



posted at: 19: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.