Contents tagged with C#

  • Using async in web forms

    Tags: async, C#

    The .aspx markup<%@ Page Title="Async" Language="C#" CodeBehind="Async.aspx.cs" Inherits="Whatever" Async="true" %> The C# code behind: public void Page_Load(object sender, EventArgs e) { … more

  • Exception Handling in C# 6.0

    Tags: .Net, C#, C# 6.0, Exception Handling

    In C# 6 the exception condition/ exception filters feature was added.try { // work } catch (Exception ex) when ( /* filter expression */ ) { //handle exception } The general rule is: … more

  • Converting Stream to String and back

    Tags: C#, string, stream

    I want to serialize objects to strings, and back.string test = "The sly fox ..."; // convert string to stream byte[] byteArray = Encoding.ASCII.GetBytes(test); MemoryStream stream = new MemoryStream( … more

  • Is there a C# IN operator?

    Tags: C#, In operator, .Net, In keyword

    The short answer is “No”. The long answer is you can achieve a similar result using extension methods:/// <summary> /// Array extention methods /// </summary> public static class … more

  • Reverse sentence word order

    Tags: C#

    This is a fairly common task and the are a lot of solutions out there.One of the more efficient ones would be using the StringBuilder class:static void Main(string[] args) { string sentence = … more

  • How to verify multiple Excel columns are equal

    Tags: Excel, Equals, C#

    Let’s say we want to compare columns A, B, C and D in row one. The corresponding formula would be:=IF(A1=B1=C1=D1, "Y","N")Unfortunately this will not work. Here’s how this formula should evaluate:= … more

  • How to start a process from C#?

    Tags: process, C#

    Here’s what I’m trying to achieve:Start a new process for each new task.Communicate the result of the process to the parent process.How to start a new process:Process process = new Process(); // … more

  • How do I open a file in C#?

    Tags: C#, open File, launch file

    Have you ever found yourself in a situation where you have to generate a file in Visual Studio and then you have to go to the folder, find the file and open it? Possibly 1,000,000,000 times a day?…OK, … more

  • Resize Excel Table

    Tags: Office, Excel, Open XML, Open XML SDK, C#, .Net

    I’m going to show you how you can resize an existing Excel table. Let’s assume you have the following table in excel (A1:C6): And you want to resize the table to a table like … more

  • What's the difference between String and string?

    Tags: string, String, C#

    In C# the string keyword is an alias for String class in the .NET Framework. The String class represents text as a series of Unicode characters.Thus the following two lines are equivalent in C#: … more