Tutorialspoint

C# TrimStart()

using System;
class Program {
   static void Main() {
      String str ="0009678".TrimStart(new Char[] { '0' } );
      Console.WriteLine(str);
   }
}

C# Write() and WriteLine() methods

using System;
class Program {
   static void Main() {
      Console.Write("One");     
      Console.Write("Two");     
        
      // this will set a new line for the next output
      Console.WriteLine("Three");    
      Console.WriteLine("Four");       
   }
}

C# Immutable string

using System;

namespace StringApplication {

   class StringProg {
   
      static void Main(string[] args) {
         string str1 = "Steve";
         string str2 = "Ben";

         if (String.Compare(str1, str2) == 0) {
            Console.WriteLine(str1 + " and " + str2 +  " are equal strings.");
         } else {
            Console.WriteLine(str1 + " and " + str2 + " are not equal strings.");
         }
         Console.ReadKey() ;
      }
   }
}

C# Mutable string

using System;
using System.Text;
					
public class Program {
   public static void Main() {
      StringBuilder str = new StringBuilder("Web World!!",30);
      str.Replace("World", "Arena");
		
      Console.WriteLine(str);
   }
}

C# TrimEnd() method

using System;
class Program {
   static void Main() {
	
      String str ="234561111".TrimEnd(new Char[] { '1' } );
      Console.WriteLine(str);
   }
}

C# method hiding

using System;
using System.Collections.Generic;

class Demo {
   public class Parent {  
      public string GetInfo () {  
         return "This is Parent Class!";  
      }  
   }  
   public class Child : Parent {  
      public new string GetInfo() {  
         return "This is Child Class!";  
      }  
   }  
        
   static void Main(String[] args) {
      Child child = new Child();  
      Console.WriteLine(child. GetInfo());     
   }
}

C# perform arithmetic calculations

using System;

namespace OperatorsApplication {
   class Program { 
      static void Main(string[] args) { 
         int a = 40;
         int b = 20;
         int c;

         c = a + b;
         Console.WriteLine("Addition: {0}", c);
         
         c = a - b;
         Console.WriteLine("Subtraction: {0}", c);
         
         c = a * b;
         Console.WriteLine("Multiplication: {0}", c);
         
         c = a / b;
         Console.WriteLine("Division: {0}", c);
         
         Console.ReadLine();
      }
   }
}

C# Integer to String Conversions

using System;
class Program {
   static void Main() {
      int a, b, c;
      
      a = 10;
      string str = a.ToString();
      Console.WriteLine(str);
       
      b = 50;
      string str2 = Convert.ToString(b);
      Console.WriteLine(str2);

      c = 100;
      string str3 = string.Format("{0}", c);
      Console.WriteLine(str3);
   }
}

C# new keyword

using System;
class Program {
   static void Main() {
	
      int[] arrSource = new int[4];
      arrSource[0] = 5;
      arrSource[1] = 9;
      arrSource[2] = 1;
      arrSource[3] = 3;
        
      int[] arrTarget = new int[4];
        
      // CopyTo() method
      arrSource.CopyTo(arrTarget,0 );

      Console.WriteLine("Destination Array ...");
      foreach (int value in arrTarget) {
         Console.WriteLine(value);
      }
   }
}

C# Remove Leading Zeros from a String

using System;
class Program {
   static void Main() {
	
      String str ="000234".TrimStart(new Char[] { '0' } );
      Console.WriteLine(str);
   }
}

Advertisements
Loading...