---
title: "Compare text file contents to a string variable using C#"  
description: "Compare text file contents to a string variable using C#"  
author: "Aaron Douglas"  
published: 2013-10-16  
updated: 2013-10-16  
canonical: https://www.mindstick.com/forum/1696/compare-text-file-contents-to-a-string-variable-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Compare text file contents to a string variable using C#

How can I [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) a [text file](https://www.mindstick.com/forum/12828/converting-a-text-file-to-an-array-in-java) contents to a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) using c#

## Replies

### Reply by Anonymous User

var fileContents = [File](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp).ReadAllText(fileName);

return testString == filecontents;


---

Original Source: https://www.mindstick.com/forum/1696/compare-text-file-contents-to-a-string-variable-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
