Click here to Skip to main content
13,298,481 members (65,588 online)
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 24 Aug 2006

A Generic Diff/Patch Utility written in C#

, 27 May 2009
Rate this:
Please Sign up or sign in to vote.
Generic Diff/Patch Utility written in C#

Download - 7.82 KB


Have you ever wanted or needed a diff utility optimized for the .NET platform.

This article provides an implementation of a diff utility written in C#.

It operates over generics, so you can provide lists of anything to be diffed or patched,
including strings (such as lines from files), int, objects, or even bytes.

Example of using the Diff class to diff 2 text files

List<string> a = new List<string>();

List<string> b = new List<string>();

StreamReader fs1 = new StreamReader(argv[0]);

StreamReader fs2 = new StreamReader(argv[1]);

string line;

while ((line = fs1.ReadLine()) != null)




while ((line = fs2.ReadLine()) != null)






Item[] diff_items = Diff2.Diff<string>(a.ToArray(), b.ToArray());

This performs the diff. The final parameter indicates whether the actual differences should be included in the edit script when the diff is performed.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

kevin delafield
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 2 Pin
gam6it28-Jul-11 23:33
membergam6it28-Jul-11 23:33 
GeneralSeems very similar to another one. Pin
Vladimir Vasiltsov17-Feb-10 11:03
memberVladimir Vasiltsov17-Feb-10 11:03 
GeneralFile Formats Pin
SCADirector3-Jan-08 9:54
memberSCADirector3-Jan-08 9:54 
QuestionDid you test this??? Pin
DARKHalf4-Feb-07 2:41
memberDARKHalf4-Feb-07 2:41 
AnswerRe: Did you test this??? Pin
AutoDeveloper17-May-07 4:05
memberAutoDeveloper17-May-07 4:05 
QuestionRe: Did you test this??? Pin
mrwizard82d126-Jul-07 18:42
membermrwizard82d126-Jul-07 18:42 
AnswerRe: Did you test this??? Pin
kevin delafield27-May-09 23:27
memberkevin delafield27-May-09 23:27 
GeneralRe: Did you test this??? Pin
mrwizard82d128-May-09 5:42
membermrwizard82d128-May-09 5:42 
GeneralMore Information Pin
Steve Hansen24-Aug-06 23:25
memberSteve Hansen24-Aug-06 23:25 
GeneralRe: More Information Pin
diilbert25-Aug-06 3:30
memberdiilbert25-Aug-06 3:30 
GeneralRe: More Information Pin
Steven Roebert25-Aug-06 12:10
memberSteven Roebert25-Aug-06 12:10 
GeneralRe: More Information Pin
PIEBALDconsult15-Dec-06 4:34
memberPIEBALDconsult15-Dec-06 4:34 
GeneralRe: More Information Pin
kevin delafield27-May-09 23:27
memberkevin delafield27-May-09 23:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 28 May 2009
Article Copyright 2006 by kevin delafield
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid