This repository was archived by the owner on Aug 5, 2024. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
Language: C#
        Neil Fraser edited this page Feb 10, 2018 
        ·
        1 revision
      
    Each language port of Diff Match Patch uses the same API. These are the language-specific notes regarding C#.
C# can be executed either with Microsoft's Visual Studio, or with Mono. This documentation uses Mono.
Here's a minimal example of a diff in C#:
using DiffMatchPatch;
using System;
using System.Collections.Generic;
public class hello {
  public static void Main(string[] args) {
    diff_match_patch dmp = new diff_match_patch();
    List<Diff> diff = dmp.diff_main("Hello World.", "Goodbye World.");
    // Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")]
    dmp.diff_cleanupSemantic(diff);
    // Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")]
    for (int i = 0; i < diff.Count; i++) {
      Console.WriteLine(diff[i]);
    }
  }
}Go to the csharp directory and save the above program as hello.cs.  Then execute two commands:
mcs hello.cs DiffMatchPatch.cs
mono hello.exe
Unit tests can be performed from the csharp/tests directory by executing two commands:
mcs DiffMatchPatchTest.cs ../DiffMatchPatch.cs
mono DiffMatchPatchTest.exe
All tests should pass.
Speed test for diff can be performed from the csharp/tests directory by two commands:
mcs Speedtest.cs ../DiffMatchPatch.cs
mono Speedtest.exe