DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets

  • submit to reddit

Recent Snippets

                    
string strReverse ="";
string straoriginal = "Test";
string strReverse= Microsoft.VisualBasic.Strings.StrReverse(strOriginal);
    MessageBox.Show(strReverse); 
                
                    
Progessive form 
IEnumerable<string> filtered   = names.Where      (n => n.Contains ("a"));
IEnumerable<string> sorted     = filtered.OrderBy (n => n.Length);
IEnumerable<string> finalQuery = sorted.Select    (n => n.ToUpper());
Output

Harry
Mary
Jay

Jay
Mary
Harry

JAY
MARY
HARRY
 
 
 

 
 

                
                    
string string1= "Split function";
string [] SplitString = string1.Split(new Char [] {' '});
MessageBox.Show(Convert.ToString(SplitString [0]));
MessageBox.Show(Convert.ToString(SplitString [1])); 
                
                    Fluent query - LINQ

string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };

IEnumerable<string> query = names
	.Where   (n => n.Contains ("a"))
	.OrderBy (n => n.Length)
	.Select  (n => n.ToUpper());
                
                    Simple Filter Query 
from n in new[] { "Tom", "Dick", "Harry" }
where n.Contains ("a")
select n

Ouput: Harry                
                    
string string1 = "Replace string";
string finalstring= string1 .Replace("replace", "Replaced");
MessageBox.Show("Final Value : " + finalstring); 
                
                    Extension method

(new[] {"T", "D", "H"} ).Where (n => n.Length >= 4)
                
                    
string string1= "This is a substring function";
string search= "sub";
int charFirst= string1.IndexOf(search);
MessageBox.Show("String at : " + charFirst); 
                
                    // description of your code here

string[] names = { "T", "D", "H" };

IEnumerable<string> filteredNames =
	System.Linq.Enumerable.Where (names, n => n.Length >= 4);
                                    
foreach (string n in filteredNames)
	Console.Write (n + "|");code>                
                    
int[] listA= { 1,2,3}; 
int[] ListB = { 1,5,6,4}; 
  
    var result = listA.Except(listB); 
  
    foreach (var n in result) 
    { 
        Console.WriteLine(n); 
    }