Breaking News
Home / .NET / CSharp / CSharp Snippets

CSharp Snippets

Building a Simple Web Server using C#.NET

Visual Studio .Net framework provides you enough resources to write your own web server. Of course a web server for real life usage should be very robust and sophisticated. But first we’ll see how we can get around creating the most fundamental web server using C#.Net. This article explains the …

Read More »

How to generate a random number in CSharp?

In order to generate a random number between two numbers, use the Next Function of the Random class as shown below: Example : To simulate a roll of a dice, we would need to generate a random integer between 1 and 6 (6 not included). Random random = new Random();int …

Read More »

How do you convert Image in Base64 String to actual Image in C#?

Code Snippet public Image Base64ToImage(string base64String) {   // Convert Base64 String to byte[]   byte[] imageBytes = Convert.FromBase64String(base64String);   MemoryStream ms = new MemoryStream(imageBytes, 0,     imageBytes.Length);   // Convert byte[] to Image   ms.Write(imageBytes, 0, imageBytes.Length);   Image image = Image.FromStream(ms, true);   return image; } <!

Read More »

How do you convert Image to Base64 String in C#?

Code Snippet public string ImageToBase64(Image image,   System.Drawing.Imaging.ImageFormat format) {   using (MemoryStream ms = new MemoryStream())   {     // Convert Image to byte[]     image.Save(ms, format);     byte[] imageBytes = ms.ToArray();     // Convert byte[] to Base64 String     string base64String = Convert.ToBase64String(imageBytes); …

Read More »
Advertisment ad adsense adlogger