Add Extension method : Extension Method : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » Extension Method »

 

Add Extension method








    
 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
public static class Extensions {
    public static string SpaceToUnderscore(this string source) {
        char[] cArray = source.ToCharArray();
        string result = null;

        foreach (char c in cArray) {
            if (Char.IsWhiteSpace(c))
                result += "_";
            else
                result += c;
        }

        return result;
    }
}
class Program {
    static void Main(string[] args) {
        string s = "This is a test";
        Console.WriteLine(s.SpaceToUnderscore());
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» Extension Method