Padding character with string

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Padding { class Program { static void Main(string[] args) { string str = “This is a text”; char padChar = ‘.’; Console.WriteLine(str.PadLeft(25, padChar)); Console.WriteLine(str.PadLeft(2, padChar)); Console.WriteLine(str.PadRight(25, padChar)); Console.WriteLine(str.PadRight(2, padChar)); str = “I am Mahedee hasan. Software Architect, Leadsoft Bangladesh Ltd”; Console.WriteLine((str.PadRight(25, padChar))); Console.WriteLine((str.PadRight(25,padChar)).Substring(0,24)+”…”); Console.ReadKey();

Read More

Iterator Design Pattern with C#

Iterator pattern is a design pattern which is used to traverse aggregate object often called container and access container’s object without exposing it’s underlying representation. Iterator pattern decoupled algorithm from aggregate object or container. In some cases, algorithms are container specific. We often use collection in C# and then we traverse the collection without knowing

Read More

How to send email in ASP.net

ou have to configure SMTP server before sending email from your server. Hope you already know how to configure smtp server. Here is the simple code segment for sending email against a button click. protected void btnSendMail_Click(object sender, EventArgs e) { SmtpClient smtpClient = new SmtpClient(); MailAddress fromAddress = new MailAddress(“mahedee_hasan@leads-bd.com”); //Sender email address MailMessage

Read More

Calculate file checksum using c#

Calculate file checksum using c# using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace CheckSumTest { class Program { static void Main(string[] args) { string filePath = @”G:\Mahedee_Share\Created\23062014-1\FileDeployManager\FileDeployManager\Form1.cs”; string checksumMd5 = GetFileChecksum(filePath, Algorithms.MD5); string checksumSha1 = GetFileChecksum(filePath, Algorithms.SHA1); string checksumSha256 = GetFileChecksum(filePath, Algorithms.SHA256); string checksumSha384 = GetFileChecksum(filePath, Algorithms.SHA384); string

Read More

Strategy Design Pattern with C#

Strategy design pattern is a behavioral design pattern. It is a particular software design pattern where algorithms are selected at runtime. According to the book of Design Pattern (Gang of Four) – “Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Read More

Abstract Factory Pattern with C#

Abstract factory pattern is a creational design pattern. Creational design pattern is deals with object creation mechanism. Object creation mechanism is changed on the basis of problem. Abstract factory pattern provides an interface to create families of related or dependent objects without specifying their concrete class. It is identified on the basis of problem complexity.

Read More

Factory Design Pattern with C#

Factory design pattern implements the concept of real world factories. Factory pattern is a creational design pattern. It deals with creating object without specifying exact class. In general, actors of factory patterns are a client, a factory and a product. Client is an object that requires another object for some purposes. Rather than creating the

Read More

How to copy folder with content with C#

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CopyFolder { class Program { static void Main(string[] args) { string sourcePath = @”G:\Mahedee_Share\Created”; string destPath = @”G:\Mahedee_Share\Development”; CopyFolder(sourcePath,destPath); } private static void CopyFolder(string sourcePath, string destinationPath) { try { //Now Create all of the directories foreach (string dirPath in Directory.GetDirectories(sourcePath, “*”,

Read More

Love Calculator using C#

Love Calculator public class LoveCalculator { public string GetResults(string name1, string name2) { return GetCount(name1, name2); } private string GetCount(string firstName, string secondName) { try { string first = firstName.ToUpper(); int firstlength = firstName.Length; string second = secondName.ToUpper(); int secondlength = secondName.Length; int LoveCount = 0; for (int Count = 0; Count < firstlength; Count++)

Read More

How to remove special character from Unicode string

Here is the sample code to remove special character from Unicode string. Sample Input: SG@%@sgs th? g#%@^@#$ chào^#^$#!abc35| _ sgs _35 hello world không gsg Sample Output: SG%sgs th? g#%^#$ chào^#^$#!abc35 sgs 35 hello world không gsg class Program { static void Main(string[] args) { string inputString = “SG@%@sgs thể g#%@^@#$ chào^#^$#!abc35| _ sgs _35

Read More

How to check Palindrome word using C#

Palindrome word can be read in both direction. Suppose “level” can be read in both direction, so it is palindrome word. To check palindrome word you can try like following code using C#. class Program { public static bool IsPalindrome(string word) { int minLength = 0; int maxLength = word.Length – 1; while (true) {

Read More

Draw star pyramid using C#

Sample input: 5 Sample output: Code: /*Author: Md. Mahedee Hasan*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StarPyramid { class Program { static void Main(string[] args) { Console.WriteLine(“Enter a number to draw pyramid: “); int nRow = 0; nRow = Convert.ToInt32(Console.ReadLine()); for (int row = 1; row