---
title: "What is the difference between 'String' and 'string' in C#?"  
description: "What is the difference between 'String' and 'string' in C#?"  
author: "Ravi Vishwakarma"  
published: 2024-06-11  
updated: 2024-06-11  
canonical: https://www.mindstick.com/interview/33901/what-is-the-difference-between-string-and-string-in-c-sharp  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 3 minutes  

---

# What is the difference between 'String' and 'string' in C#?

**String (with capital 'S')**:

- 'String' refers to the .NET Framework **class** representing a string of characters. It's part of the System namespace: `System.String`.
- As a class, 'String' provides various methods and properties for working with strings, such as `Substring()`, `Length`, `IndexOf()`, etc.
- It's generally used when referring to the class itself or when you need to specify the type explicitly.

**string (with lowercase 's')**:

- 'string' is a C# keyword and an alias for the 'String' class. It's used to declare variables that hold string data.
- It's commonly used when declaring variables, parameters, or return types dealing with string data.
- Since C# is case-sensitive, 'string' is not interchangeable with 'String' when specifying types. It's purely a syntactical difference.

Here's an example demonstrating the use of 'String' and 'string':

```cs
using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            String str1 = "Hello";  // Using String class explicitly
            string str2 = "World";  // Using string keyword

            // Both variables hold the same type of data
            Console.WriteLine(str1);  // Output: Hello
            Console.WriteLine(str2);  // Output: World
        }
    }
}
```

In practice, you'll often see 'string' used for variable declarations and 'String' used when referring to the class itself or when explicit type specification is necessary. However, both refer to the same string data type in C#.

## Answers

### Answer by Ravi Vishwakarma

**String (with capital 'S')**:

- 'String' refers to the .NET Framework **class** representing a string of characters. It's part of the System namespace: `System.String`.
- As a class, 'String' provides various methods and properties for working with strings, such as `Substring()`, `Length`, `IndexOf()`, etc.
- It's generally used when referring to the class itself or when you need to specify the type explicitly.

**string (with lowercase 's')**:

- 'string' is a C# keyword and an alias for the 'String' class. It's used to declare variables that hold string data.
- It's commonly used when declaring variables, parameters, or return types dealing with string data.
- Since C# is case-sensitive, 'string' is not interchangeable with 'String' when specifying types. It's purely a syntactical difference.

Here's an example demonstrating the use of 'String' and 'string':

```cs
using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            String str1 = "Hello";  // Using String class explicitly
            string str2 = "World";  // Using string keyword

            // Both variables hold the same type of data
            Console.WriteLine(str1);  // Output: Hello
            Console.WriteLine(str2);  // Output: World
        }
    }
}
```

In practice, you'll often see 'string' used for variable declarations and 'String' used when referring to the class itself or when explicit type specification is necessary. However, both refer to the same string data type in C#.


---

Original Source: https://www.mindstick.com/interview/33901/what-is-the-difference-between-string-and-string-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
