dir.by  
  Поиск  
Компьютер, программы
C# (programming language)
Text in C# (type string and class String)
 What is text in the C# ? Type string and class String. Methods for working with text. 
посмотрели 16124 раз
обновлено: 27 November 2018
To work with text in the C# type used string
  C#     Example
string myText = "Hello";
Methods of working with text are in the classroom String.
Type string is a class alias String.
That is, when we write:
string myText = "Hello";
we can use class methods and variables String.

For example, get the length of a string
int len = myText.Length;

or call the
book isSame = myText.CompareTo("House");

Text in the C# it is a sequence of characters Unicode.
Maximum object size String Can be 2 GB in memory, or about 1 billion characters.
Properties of class String
Length
String length (number of characters)
  C#     Example
string str1 = "Hello";
int v1 = str1.Length;
// v1 = 5
Methods of class String
CompareTo
Compares case-sensitive text
Learn more: CompareTo ...
  C#     Example
string str1 = "Hello";
string str2 = "Hello";
bool bIsSame = str1.CompareTo(str2)==0;
// bIsSame = true
ToLower
Converts text to lowercase (in small letters)
Learn more: ToLower...
  C#     Example
string str1 = "HELLO World!";
string str2 = str1.ToLower();
// str1 = "HELLO World!"
// str2 = "hello world!"
ToUpper
Converts text to uppercase (in capital letters)
Learn more: ToUpper...
  C#     Example
string str1 = "Hello World!";
string str2 = str1.ToUpper();
// str1 = "Hello World!"
// str2 = "HELLO WORLD!"
Split
Splits text into words using a separator
Learn more: Split...
  C#     Example
string text = "Hello! How do you do?"

string[] words = text.Split(' '); 
// array words: 
// words[0] = "Hello!" 
// words[1] = "How" 
// words[2] = "do" 
// words[3] = "you" 
// words[4] = "do?"
StartsWith
Checks the beginning of text with specified text (case sensitive)
Learn more: StartsWith ...
  C#     Example 1
string str1 = "Hello world!";
string str2 = "He";
bool bStart = str1.StartsWith(str2);
// bStart = true


  C#     Example 2
string str1 = "Hello world!";
string str2 = "HE";

// case-insensitive
bool bStart = str1.StartsWith(str2, StringComparison.OrdinalIgnoreCase);
// bStart = true
Contains
Checks whether the specified text contains text or not (case sensitive)
Learn more: Contains ...
  C#     Example
string str1 = "Hello world!";
string str2 = "ello";
bool bFound = str1.Contains(str2);
// bFound = true
IndexOf
Looks for case-sensitive text and returns the position
Learn more: IndexOf ...
  C#     Example
string str1 = "Hello world!";
string str2 = "lo";
int pos = str1.IndexOf(str2);
// pos = 3
Substring
returns part of the text from the specified position and length
Learn more: Substring ...
  C#     Example
string str1 = "Hello World!";
string str2 = str1.Substring(2, 5);
// str2 = "llo W"
IsNullOrEmpty
checks the text for blank or for null
Learn more: IsNullOrEmpty ...
  C#     Example
string name = "";
bool bIsEmpty = String.IsNullOrEmpty(name);
// bIsEmpty = true

IsNullOrWhiteSpace
validates text on null or on spaces
Learn more: IsNullOrWhiteSpace ...
  C#     Example
string name = "   ";
bool bIsEmpty = String.IsNullOrWhiteSpace(name);
// bIsEmpty = true
[]
returns a character from the specified position
Learn more: [] ...
  C#     Example
string str = "Hello World!";
char symbol = str[1];
// symbol = 'e'
String.Format
formatting a string (replaces text with objects)
Learn more: Format ...
  C#     Example
string name = "Petr";
int year = 45;
string str = String.Format("Hello {0}, {1}", name, year);
// str = "Hello Petr, 45"
+
add text
Learn more: + ...
  C#     Example
string str1 = "Hello";
string str2 = "word";
string str = str1 + str2 + " people!";
// str = "Hello word people!"
$
string interpolation
Learn more: $ ...
  C#     Example
int a = 5;
int b = 7;
string result = $"{a} + {b} = {a + b}";
// str = "5 + 7 = 12"
Note!
Even though the type string is a reference type , equality operators (== and !=) defined for comparison of values, not links.
This makes it easier to check strings for equality.
  C#     Let's create a new console application on C#... and write the code
using System;

namespace ConsoleApplication1
{
     class Program
     {
          static void Main(string[] args)
          {
               // text
               string str1 = "aaa";
               string str2 = "aaa";

               // Equal ?
               bool isEqual = str1 == str2;
               // isEqual = true
          }
     }
}
class String (all methods and properties)
String is a class that represents text as a sequence of characters Unicode.

namespace System

Version .NETFramework\v4.6.1\mscorlib.dll

Syntax
public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable, IComparable<string>, IEnumerable<char>, IEquatable<string>
Constructors
public String(char* value);
Initializes a new instance of the System.String class to the value indicated by a specified pointer to an array of Unicode characters. Read more ...
public String(char[] value);
Initializes a new instance of the System.String class to the value indicated by an array of Unicode characters. Read more ...
public String(sbyte* value);
Initializes a new instance of the System.String class to the value indicated by a pointer to an array of 8-bit signed integers. Read more ...
public String(char c, int count);
Initializes a new instance of the System.String class to the value indicated by a specified Unicode character repeated a specified number of times. Read more ...
public String(char* value, int startIndex, int length);
Initializes a new instance of the System.String class to the value indicated by a specified pointer to an array of Unicode characters, a starting character position within that array, and a length. Read more ...
public String(char[] value, int startIndex, int length);
Initializes a new instance of the System.String class to the value indicated by an array of Unicode characters, a starting character position within that array, and a length. Read more ...
public String(sbyte* value, int startIndex, int length);
Initializes a new instance of the System.String class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting position within that array, and a length. Read more ...
public String(sbyte* value, int startIndex, int length, Encoding enc);
Initializes a new instance of the System.String class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting position within that array, a length, and an System.Text.Encoding object. Read more ...

Properties
public static readonly string Empty;
Represents the empty string. This field is read-only.
public int Length { get; }
Gets the number of characters in the current System.String object. Read more ...
public char this[int index] { get; }
Gets the System.Char object at a specified position in the current System.String object. Read more ...

Methods
public static bool operator !=(string a, string b);
Determines whether two specified strings have different values. Read more ...
public static bool operator ==(string a, string b);
Determines whether two specified strings have the same value. Read more ...
public object Clone();
Returns a reference to this instance of System.String. Read more ...
public static int Compare(string strA, string strB);
Compares two specified System.String objects and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, string strB, bool ignoreCase);
Compares two specified System.String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, string strB, StringComparison comparisonType);
Compares two specified System.String objects using the specified rules, and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, string strB, bool ignoreCase, CultureInfo culture);
Compares two specified System.String objects, ignoring or honoring their case, and using culture-specific information to influence the comparison, and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, string strB, CultureInfo culture, CompareOptions options);
Compares two specified System.String objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two strings to each other in the sort order. Read more ...
public static int Compare(string strA, int indexA, string strB, int indexB, int length);
Compares substrings of two specified System.String objects and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase);
Compares substrings of two specified System.String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, int indexA, string strB, int indexB, int length, StringComparison comparisonType);
Compares substrings of two specified System.String objects using the specified rules, and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture);
Compares substrings of two specified System.String objects, ignoring or honoring their case and using culture-specific information to influence the comparison, and returns an integer that indicates their relative position in the sort order. Read more ...
public static int Compare(string strA, int indexA, string strB, int indexB, int length, CultureInfo culture, CompareOptions options);
Compares substrings of two specified System.String objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two substrings to each other in the sort order. Read more ...
public static int CompareOrdinal(string strA, string strB);
Compares two specified System.String objects by evaluating the numeric values of the corresponding System.Char objects in each string. Read more ...
public static int CompareOrdinal(string strA, int indexA, string strB, int indexB, int length);
Compares substrings of two specified System.String objects by evaluating the numeric values of the corresponding System.Char objects in each substring. Read more ...
public int CompareTo(object value);
Compares this instance with a specified System.Object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified System.Object. Read more ...
public int CompareTo(string strB);
Compares this instance with a specified System.String object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified string. Read more ...
public static string Concat(IEnumerable<string> values);
Concatenates the members of a constructed System.Collections.Generic.IEnumerable<T> collection of type System.String. Read more ...
public static string Concat<T>(IEnumerable<T> values);
Concatenates the members of an System.Collections.Generic.IEnumerable<T> implementation. Read more ...
public static string Concat(object arg0);
Creates the string representation of a specified object. Read more ...
public static string Concat(params object[] args);
Concatenates the string representations of the elements in a specified System.Object array. Read more ...
public static string Concat(params string[] values);
Concatenates the elements of a specified System.String array. Read more ...
public static string Concat(object arg0, object arg1);
Concatenates the string representations of two specified objects. Read more ...
public static string Concat(string str0, string str1);
Concatenates two specified instances of System.String. Read more ...
public static string Concat(object arg0, object arg1, object arg2);
Concatenates the string representations of three specified objects. Read more ...
public static string Concat(string str0, string str1, string str2);
Concatenates three specified instances of System.String. Read more ...
public static string Concat(object arg0, object arg1, object arg2, object arg3);
Concatenates the string representations of four specified objects and any objects specified in an optional variable length parameter list. Read more ...
public static string Concat(string str0, string str1, string str2, string str3);
Concatenates four specified instances of System.String. Read more ...
public bool Contains(string value);
Returns a value indicating whether a specified substring occurs within this string. Read more ...
public static string Copy(string str);
Creates a new instance of System.String with the same value as a specified System.String. Read more ...
public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);
Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters. Read more ...
public bool EndsWith(string value);
Determines whether the end of this string instance matches the specified string. Read more ...
public bool EndsWith(string value, StringComparison comparisonType);
Determines whether the end of this string instance matches the specified string when compared using the specified comparison option. Read more ...
public bool EndsWith(string value, bool ignoreCase, CultureInfo culture);
Determines whether the end of this string instance matches the specified string when compared using the specified culture. Read more ...
public override bool Equals(object obj);
Determines whether this instance and a specified object, which must also be a System.String object, have the same value. Read more ...
public bool Equals(string value);
Determines whether this instance and another specified System.String object have the same value. Read more ...
public static bool Equals(string a, string b);
Determines whether two specified System.String objects have the same value. Read more ...
public bool Equals(string value, StringComparison comparisonType);
Determines whether this string and a specified System.String object have the same value. A parameter specifies the culture, case, and sort rules used in the comparison. Read more ...
public static bool Equals(string a, string b, StringComparison comparisonType);
Determines whether two specified System.String objects have the same value. A parameter specifies the culture, case, and sort rules used in the comparison. Read more ...
public static string Format(string format, object arg0);
Replaces one or more format items in a specified string with the string representation of a specified object. Read more ...
public static string Format(string format, params object[] args);
Replaces the format item in a specified string with the string representation of a corresponding object in a specified array. Read more ...
public static string Format(IFormatProvider provider, string format, object arg0);
Replaces the format item or items in a specified string with the string representation of the corresponding object. A parameter supplies culture-specific formatting information. Read more ...
public static string Format(IFormatProvider provider, string format, params object[] args);
Replaces the format items in a specified string with the string representations of corresponding objects in a specified array. A parameter supplies culture-specific formatting information. Read more ...
public static string Format(string format, object arg0, object arg1);
Replaces the format items in a specified string with the string representation of two specified objects. Read more ...
public static string Format(IFormatProvider provider, string format, object arg0, object arg1);
Replaces the format items in a specified string with the string representation of two specified objects. A parameter supplies culture-specific formatting information. Read more ...
public static string Format(string format, object arg0, object arg1, object arg2);
Replaces the format items in a specified string with the string representation of three specified objects. Read more ...
public static string Format(IFormatProvider provider, string format, object arg0, object arg1, object arg2);
Replaces the format items in a specified string with the string representation of three specified objects. An parameter supplies culture-specific formatting information. Read more ...
public CharEnumerator GetEnumerator();
Retrieves an object that can iterate through the individual characters in this string. Read more ...
public override int GetHashCode();
Returns the hash code for this string. Read more ...
public TypeCode GetTypeCode();
Returns the System.TypeCode for class System.String. Read more ...
public int IndexOf(char value);
Reports the zero-based index of the first occurrence of the specified Unicode character in this string. Read more ...
public int IndexOf(string value);
Reports the zero-based index of the first occurrence of the specified string in this instance. Read more ...
public int IndexOf(char value, int startIndex);
Reports the zero-based index of the first occurrence of the specified Unicode character in this string. The search starts at a specified character position. Read more ...
public int IndexOf(string value, int startIndex);
Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position. Read more ...
public int IndexOf(string value, StringComparison comparisonType);
Reports the zero-based index of the first occurrence of the specified string in the current System.String object. A parameter specifies the type of search to use for the specified string. Read more ...
public int IndexOf(char value, int startIndex, int count);
Reports the zero-based index of the first occurrence of the specified character in this instance. The search starts at a specified character position and examines a specified number of character positions. Read more ...
public int IndexOf(string value, int startIndex, int count);
Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position and examines a specified number of character positions. Read more ...
public int IndexOf(string value, int startIndex, StringComparison comparisonType);
Reports the zero-based index of the first occurrence of the specified string in the current System.String object. Parameters specify the starting search position in the current string and the type of search to use for the specified string. Read more ...
public int IndexOf(string value, int startIndex, int count, StringComparison comparisonType);
Reports the zero-based index of the first occurrence of the specified string in the current System.String object. Parameters specify the starting search position in the current string, the number of characters in the current string to search, and the type of search to use for the specified string. Read more ...
public int IndexOfAny(char[] anyOf);
Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. Read more ...
public int IndexOfAny(char[] anyOf, int startIndex);
Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position. Read more ...
public int IndexOfAny(char[] anyOf, int startIndex, int count);
Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position and examines a specified number of character positions. Read more ...
public string Insert(int startIndex, string value);
Returns a new string in which a specified string is inserted at a specified index position in this instance. Read more ...
public static string Intern(string str);
Retrieves the system's reference to the specified System.String. Read more ...
public static string IsInterned(string str);
Retrieves a reference to a specified System.String. Read more ...
public bool IsNormalized();
Indicates whether this string is in Unicode normalization form C. Read more ...
public bool IsNormalized(NormalizationForm normalizationForm);
Indicates whether this string is in the specified Unicode normalization form. Read more ...
public static bool IsNullOrEmpty(string value);
Indicates whether the specified string is null or an System.String.Empty string. Read more ...
public static bool IsNullOrWhiteSpace(string value);
Indicates whether a specified string is null, empty, or consists only of white-space characters. Read more ...
public static string Join(string separator, IEnumerable<string> values);
Concatenates the members of a constructed System.Collections.Generic.IEnumerable<T> collection of type System.String, using the specified separator between each member. Read more ...
public static string Join<T>(string separator, IEnumerable<T> values);
Concatenates the members of a collection, using the specified separator between each member. Read more ...
public static string Join(string separator, params object[] values);
Concatenates the elements of an object array, using the specified separator between each element. Read more ...
public static string Join(string separator, params string[] value);
Concatenates all the elements of a string array, using the specified separator between each element. Read more ...
public static string Join(string separator, string[] value, int startIndex, int count);
Concatenates the specified elements of a string array, using the specified separator between each element. Read more ...
public int LastIndexOf(char value);
Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance. Read more ...
public int LastIndexOf(string value);
Reports the zero-based index position of the last occurrence of a specified string within this instance. Read more ...
public int LastIndexOf(char value, int startIndex);
Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string. Read more ...
public int LastIndexOf(string value, int startIndex);
Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string. Read more ...
public int LastIndexOf(string value, StringComparison comparisonType);
Reports the zero-based index of the last occurrence of a specified string within the current System.String object. A parameter specifies the type of search to use for the specified string. Read more ...
public int LastIndexOf(char value, int startIndex, int count);
Reports the zero-based index position of the last occurrence of the specified Unicode character in a substring within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. Read more ...
public int LastIndexOf(string value, int startIndex, int count);
Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. Read more ...
public int LastIndexOf(string value, int startIndex, StringComparison comparisonType);
Reports the zero-based index of the last occurrence of a specified string within the current System.String object. The search starts at a specified character position and proceeds backward toward the beginning of the string. A parameter specifies the type of comparison to perform when searching for the specified string. Read more ...
public int LastIndexOf(string value, int startIndex, int count, StringComparison comparisonType);
Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for the specified number of character positions. A parameter specifies the type of comparison to perform when searching for the specified string. Read more ...
public int LastIndexOfAny(char[] anyOf);
Reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array. Read more ...
public int LastIndexOfAny(char[] anyOf, int startIndex);
Reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The search starts at a specified character position and proceeds backward toward the beginning of the string. Read more ...
public int LastIndexOfAny(char[] anyOf, int startIndex, int count);
Reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. Read more ...
public string Normalize();
Returns a new string whose textual value is the same as this string, but whose binary representation is in Unicode normalization form C. Read more ...
public string Normalize(NormalizationForm normalizationForm);
Returns a new string whose textual value is the same as this string, but whose binary representation is in the specified Unicode normalization form. Read more ...
public string PadLeft(int totalWidth);
Returns a new string that right-aligns the characters in this instance by padding them with spaces on the left, for a specified total length. Read more ...
public string PadLeft(int totalWidth, char paddingChar);
Returns a new string that right-aligns the characters in this instance by padding them on the left with a specified Unicode character, for a specified total length. Read more ...
public string PadRight(int totalWidth);
Returns a new string that left-aligns the characters in this string by padding them with spaces on the right, for a specified total length. Read more ...
public string PadRight(int totalWidth, char paddingChar);
Returns a new string that left-aligns the characters in this string by padding them on the right with a specified Unicode character, for a specified total length. Read more ...
public string Remove(int startIndex);
Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted. Read more ...
public string Remove(int startIndex, int count);
Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted. Read more ...
public string Replace(char oldChar, char newChar);
Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced with another specified Unicode character. Read more ...
public string Replace(string oldValue, string newValue);
Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string. Read more ...
public string[] Split(params char[] separator);
Splits a string into substrings that are based on the characters in an array. Read more ...
public string[] Split(char[] separator, int count);
Splits a string into a maximum number of substrings based on the characters in an array. You also specify the maximum number of substrings to return. Read more ...
public string[] Split(char[] separator, StringSplitOptions options);
Splits a string into substrings based on the characters in an array. You can specify whether the substrings include empty array elements. Read more ...
public string[] Split(string[] separator, StringSplitOptions options);
Splits a string into substrings based on the strings in an array. You can specify whether the substrings include empty array elements. Read more ...
public string[] Split(char[] separator, int count, StringSplitOptions options);
Splits a string into a maximum number of substrings based on the characters in an array. Read more ...
public string[] Split(string[] separator, int count, StringSplitOptions options);
Splits a string into a maximum number of substrings based on the strings in an array. You can specify whether the substrings include empty array elements. Read more ...
public bool StartsWith(string value);
Determines whether the beginning of this string instance matches the specified string. Read more ...
public bool StartsWith(string value, StringComparison comparisonType);
Determines whether the beginning of this string instance matches the specified string when compared using the specified comparison option. Read more ...
public bool StartsWith(string value, bool ignoreCase, CultureInfo culture);
Determines whether the beginning of this string instance matches the specified string when compared using the specified culture. Read more ...
public string Substring(int startIndex);
Retrieves a substring from this instance. The substring starts at a specified character position and continues to the end of the string. Read more ...
public string Substring(int startIndex, int length);
Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length. Read more ...
public char[] ToCharArray();
Copies the characters in this instance to a Unicode character array. Read more ...
public char[] ToCharArray(int startIndex, int length);
Copies the characters in a specified substring in this instance to a Unicode character array. Read more ...
public string ToLower();
Returns a copy of this string converted to lowercase. Read more ...
public string ToLower(CultureInfo culture);
Returns a copy of this string converted to lowercase, using the casing rules of the specified culture. Read more ...
public string ToLowerInvariant();
Returns a copy of this System.String object converted to lowercase using the casing rules of the invariant culture. Read more ...
public override string ToString();
Returns this instance of System.String; no actual conversion is performed. Read more ...
public string ToString(IFormatProvider provider);
Returns this instance of System.String; no actual conversion is performed. Read more ...
public string ToUpper();
Returns a copy of this string converted to uppercase. Read more ...
public string ToUpper(CultureInfo culture);
Returns a copy of this string converted to uppercase, using the casing rules of the specified culture. Read more ...
public string ToUpperInvariant();
Returns a copy of this System.String object converted to uppercase using the casing rules of the invariant culture. Read more ...
public string Trim();
Removes all leading and trailing white-space characters from the current System.String object. Read more ...
public string Trim(params char[] trimChars);
Removes all leading and trailing occurrences of a set of characters specified in an array from the current System.String object. Read more ...
public string TrimEnd(params char[] trimChars);
Removes all trailing occurrences of a set of characters specified in an array from the current System.String object. Read more ...
public string TrimStart(params char[] trimChars);
Removes all leading occurrences of a set of characters specified in an array from the current System.String object. Read more ...
 
← Previous topic
Algorithm for intersecting rectangles
 
Next topic →
Length (string length in C#). Example: string str1 = "Hello"; int v1 = str1.Length;
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

 
Download and install Microsoft Visual Studio
Download and install Visual Studio 2026 (for learning C#, writing programs): WPF, ASP.NET, ASP.NET Core, UWP, Maui, Xamarin, Unity, MonoGame)
Download and install Visual Studio 2022 (for learning C#, writing programs): WPF, ASP.NET, ASP.NET Core, UWP, Maui, Xamarin, Unity, MonoGame)
Download and install Visual Studio 2019 (for learning C#, writing programs: WPF, ASP.NET, ASP.NET Core, Xamarin, Unity, MonoGame)
Download and install Visual Studio 2017 (to learn C#, writing programs: WPF, ASP.NET, ASP.NET Core, Xamarin, Unity, MonoGame)
New app for learning C#
Creating a new console application to learn C#
Debugging Code
Debug.Assert(false) Debugging Code in C#
For debugging, option "Common Language Runtime Exceptions" see exceptions when a program is running C#
Attribute [Obsolete("My method is outdated. Do not use", false)] Warning when compiling code in the C#
Data Types C#
C# data types: number (bool, char, byte, int, long, float, double, decimal), text (string), enumeration (enum), class (class), structure (struct)
Structure Boolean in the C# it is a flag with values true or false (bool) and methods for conversion bool
Structure Int32 in the C# it is a signed integer (int) and methods for conversion int
Structure Single in the C# this is a floating-point number (float) and methods for conversion float
var ... Variable of any type in the C#. Example: var str = "Hello!";
Type dynamic in the C#
Default values in the C#
Storing objects in memory. Removing Objects from Memory
Reference types and value types in the C#
Stack (stack) - memory for method parameters and local variables in the C#
Heap - dynamic memory available at run time in the C#
Interface IDisposable. Write code to properly release unmanaged resources in the destructor and in the interface IDisposable in the C#
Memory. Garbage collector (garbage collector). Automatic memory freeing in the C#
C# type conversion
C# converting a string to a number (string → short, int, long, ushort, uint, ulong, float, double, decimal) | Use Culture (system settings)
C# converting a number to a string (int, double, short, ... → string) with the required accuracy
Text in C# (type string and class String)
Algorithm for intersecting rectangles
What is text in the C# ? Type string and class String. Methods for working with text.
Length (string length in C#). Example: string str1 = "Hello"; int v1 = str1.Length;
CompareTo (compares case-sensitive text in C#). Example: bool bIsSame = str1.CompareTo(str2)==0;
ToLower (converts text to lowercase in C#). Example: string str1 = "HELLO World!"; string str2 = str1.ToLower();
ToUpper (converts text to uppercase in C#). Example: string str1 = "Hello World!"; string str2 = str1.ToUpper();
Split (split the string into words in C#). Example: string[] arrWords = strText.Split(" ");
StartsWith (checks the beginning of the text with the specified case-sensitive text in C#). Example: bool bStart = str1.StartsWith(str2);
Contains (checks whether the text specified is case-sensitive or not in case-sensitive C#). Example: bool bFound = str1.Contains(str2);
IndexOf (searches for a case-sensitive string and returns the position in C#). Example: int pos = str1.IndexOf(str2);
Substring (returns part of the text from the specified position and length in the C#). Example: string str1 = "Hello World!"; string str2 = str1.Substring(2, 5);
IsNullOrEmpty (checks the text for blank or for null in the C#). Example: string name = "Hello World!"; bool bFlag = String.IsNullOrEmpty(name);
IsNullOrWhiteSpace (validates text on null or on text with spaces in the C#). Example: string name = "   "; bool bFlag = String.IsNullOrWhiteSpace(name);
[] (returns a character from the specified position in the C#). Example: char symbol = str[1];
Format (text formatting, strings in the C#). Example: string strNew = String.Format("Hello {0}, {1}", name, year);
+ (add lines and text in the C#). Example: string str = str1 + str2 + " people!";
$ (string interpolation in the C#). Example: string result = $"Hello {a} + {b} = {a + b}";
Symbol @ before the beginning of the line in the C#. Example: string str1 = @"aaa";
Use @ and $ together (C# string interpolation)
DateTime in C#
What is DateTime in C# ? Convert to a string with the format
Enumerations in C # (enum)
What is enumeration? (enum) in the C# ?
How to convert text to enum in C#
How to enumerate all elements in enum in C#
null
null value for simple types. Use ? or Nullable in the C#
Operator ?? (null-union) in the C#
try-catch
Exception handling in C#. Operator try catch finally
Classes in C# (class)
What is a class? in the C#?
Class Access Modifiers in the C#. Access modifiers for methods, properties, fields in the C#
"partial class" in the C#. Description of the class in different files
[bgcolor=#F5F9DB]Constructors for a class[/bgcolor]
Class Constructor in the C#
Initializing a Class Object (set values for fields) in the C#
To call the constructor at the base class in the C#
Static constructor in class C#
"base" To call a method from the base class. To call a variable from the base class. To call the constructor from the base class. C#
"this" To set or get a value from a class field. To call the constructor from the class. C#
[bgcolor=#F5F9DB]Class Destructors[/bgcolor]
Class Destructor in the C#
Destructors in classrooms (how basic destructors are called) C#
[bgcolor=#F5F9DB]Inheritance[/bgcolor]
What is class inheritance in C# ?
[bgcolor=#F5F9DB]Inheritance using new[/bgcolor]
Use new for the interface method. Inheriting an interface from an interface with the same method
Use new for the class method. Inheriting a class from a class in C#.
[bgcolor=#F5F9DB]Inheritance using sealed[/bgcolor]
sealed class. Prohibition to inherit in the C#
Inheriting a class from a class in C#. We use words virtual, override, sealed for class methods
[bgcolor=#F5F9DB]Abstract class[/bgcolor]
What is an abstract class? in the C# ? Abstract methods, properties, indexes.
Inheritance from a class abstract in the C#. Use abstract and override for class methods
[bgcolor=#F5F9DB]Constants and readonly [E_M_P_T_Y] fields in the classroom[/bgcolor]
Constants in the classroom C#
readonly . For a class field. This field is read-only in C#
[bgcolor=#F5F9DB]Properties get and set in the classroom C# (accessors)[/bgcolor]
get set Properties in a class C#
Inheritance (virtual, override) for get and set accessors in C#
[bgcolor=#F5F9DB]Operators, indexers in C#[/bgcolor]
Operators in a C# class. Operator overload: > < ++ + true false
Indexers in Class C#
[bgcolor=#F5F9DB]Nested types in C#[/bgcolor]
Nested class, structure in C#
[bgcolor=#F5F9DB]Parameters in the C#[/bgcolor] class method
ref and out (return parameters by reference in the C# method). Example: public void AddValue(ref int value)
Default parameters (optional parameters) in a C# method. Example: public int CalculateSum(int a, int b, int c=7)
C# named parameters. Example: public void CalculateSum(a:7, b:3);
[bgcolor=#F5F9DB]Generic methods, generic classes in C# (templates)[/bgcolor]
A method with generic parameters in C# (templates). Example: public double Sum<T1, T2>(T1 value1, T2 value2) { ... }
A generic (typed) class in C# (templates). Example of a class Book<T> { ... }
where Type constraint in a generic (typed) class in C# (templates). Example of class Dog<T> where T : Cat
[bgcolor=#F5F9DB]Converting a class object from one type to another[/bgcolor]
explicit is an explicit conversion operator in the C class#
implicit is an implicit conversion operator in class C#
Converting a class object from one type to another in C#. Use try( ) is as
Converting a class object from one type to another in C#. Using pattern matching is switch
[bgcolor=#F5F9DB]Class object in C#[/bgcolor]
? conditional null operator in C#
The class object contains a reference in C#
How do you copy objects in C# to copy class data instead of a reference?
[bgcolor=#F5F9DB]Static constructor and static properties and methods[/bgcolor]
Static constructor in class C#
Static methods, properties, members in class C#
[bgcolor=#F5F9DB]Additional class features in C#[/bgcolor]
The extension method in C# (this in the first parameter of the method). Example: static public void AddValues(this List<int> myList, int value1, int value2)
[bgcolor=#F5F9DB]Class naming conventions in C#[/bgcolor]
What letters, lowercase or uppercase, to call classes, methods, properties... in C#
Is it correct to create a separate .cs file for each class in C#? Or write C# classes in a single .cs file?
Static Class
Static Class in C#
Anonymous Class
An object with an anonymous (missing) type in C#. Example: var book = new { BookName = "Lord of the Rings", Price = 100 };
Interfaces
What is interface in C#?
Inheriting the interface from the interface in C#
Inheriting a class from an interface class in C#. Using override and virtual for class methods
Generalized (typed) interface in C# (templates). Example interface IUser<T> { ... }
Struct structure
What is a structure in C#?
Structure access modifiers in C#. Access Modifiers for Methods, Properties, Struct Fields in C#
Initializing a Structure Object (Setting Values for Fields) in C#
How to change the value in an array of structures or in a collection of structures (List) in C#
Nested structure in C#
[bgcolor=#F5F9DB]Converting a struct object from one type to another[/bgcolor]
implicit is an implicit struct-to-C conversion operator#
explicit is an explicit struct-to-C conversion operator#
Lazy class loading in C#
Lazy Object Creation in Memory (class Lazy in C#)
Tuples
Tuples in C#
Dynamic objects with any properties
DynamicObject and ExpandoObject in C#
Arrays
What are arrays? array in C#
Initializing an Array (Populating the Array Elements) in C#
params passing any number of parameters to a method in C#
Array class C#
Collection
What are collections in C#?
What are non-generic collections in C#? ArrayList, Stack, Queue, Hashtable, SortedList, BitArray classes
What are generic (typed) collections in C#? The classes are List<T>, SortedList<T>, Stack<T>, Dictionary<TKey, TValue>, LinkedList<T>, Queue<T>, HashSet<T>, SortedSet<T>, ConcurrentDictionary<TKey, TValue>, SortedDictionary<TKey, TValue>
Non-generic collection classes (different types of items are stored in the same collection)
IEnumerable interface. The most basic interface for collections in C#
Interfaces: ICollection, IList, IDictionary. The basis for collections in C#
ArrayList class (collection in C#)
What is ArrayList in C#?
SortedList class (collection in C#)
What is SortedList in C#?
Stack class (collection in C#)
What is Stack in C# ?
Queue class (collection in C#)
What is Queue in C# ?
Hashtable class (collection in C#)
What is a Hashtable in C# ?
BitArray class (collection in C#)
What is BitArray in C#?
Generic, typed collection classes in C# (elements of the same type are stored in the same collection)
IEnumerable interface<T>. The most basic interface for typed collections in C#
Interfaces: ICollection<T>, IList<T>, ISet<T>, IDictionary<TKey, TValue>. Basis for typed collections in C#
List class<T> (typed collection in C#)
What is List<T> in C#?
Initializing the Collection List in curly brackets in the C#
for, foreach (go through all the items in the List<T>) in C#
Find (looking for an item by criterion in the List<T>) in C#
FindAll (looking for a list of items by criterion in the List<T>) in C#
ForEach (for each List element an<T> action is performed) in C#
LinkedList class<T> (typed collection in C#)
What is LinkedList<T> in C# ?
SortedList<TKey, TValue> class (typed collection in C#)
What is SortedList<TKey, TValue> in C# ?
Stack class<T> (typed collection in C#)
What is Stack<T> in C# ?
Queue class<T> (typed collection in C#)
What is Queue<T> in C# ?
HashSet class<T> (typed collection in C#)
What is a HashSet<T> in C# ?
How HashSet works<T> in C#
SortedSet class<T> (typed collection in C#)
What is a SortedSet<T> in C#?
ObservableCollection class<T> (typed collection in C#)
What is ObservableCollection<T> in C#?
Dictionary<TKey, TValue> class (typed collection in C#)
What is Dictionary<TKey, TValue> in C# ?
Initializing Elements in the Dictionary<TKey, TValue> Constructor in C#
How Dictionary<TKey, TValue> works in C#
How to convert IEnumerable to → Dictionary in C#<TKey, TValue> . Using the ToDictionary method
SortedDictionary<TKey, TValue> class (typed collection in C#)
What is SortedDictionary<TKey, TValue> in C# ?
ConcurrentDictionary<TKey, TValue> class (typed collection in C#)
What is ConcurrentDictionary<TKey, TValue> in C# ?
AddOrUpdate (add or update a value by key in ConcurrentDictionary<TKey, TValue>) in C#
Asymptotic complexity for adding, removing, taking an item in collections
Asymptotic complexity for adding, removing, taking an element in collections C# (List, SortedList, Stack, Dictionary, LinkedList, Queue, HashSet, SortedSet, ConcurrentDictionary, SortedDictionary)
Sorting Elements in the [] Array and List <T>Collection
Sorting elements in the [] array and List collection<T> in C#. IComparable interface
Sorting elements in the [] array and List collection<T> in C#. IComparer interface
My implementation of IEnumerator, IEnumerable, and iterators
Example: My implementation of the IEnumerable and IEnumerator interfaces in C#
Iterators and yield in C#. Examples of IEnumerable implementation with yield
Extension Methods for IEnumerable<T> (Search, Replace, Value Sampling) in C#
Methods for finding, replacing, and fetching values in IEnumerable<T>. Extension methods for IEnumerable<T> in C#
Any (IEnumerable extension method<T>) in C#
Select (IEnumerable extension method<T>) in C#
GroupBy (extension method IEnumerable<T>) in the C#
GroupJoin (extension method IEnumerable<T>) in the C#
Sorting, filtering in LINQ (Language-Integrated Query)
What is LINQ in C#?
Sorting, filtering list items using LINQ in C#
Books for learning LINQ in C#
Pointers
Pointers in C#. Operator unsafe
Pointers to structs, class fields, arrays in C#. Operators unsafe, stackalloc, fixed
Working with files
Open the file, read the text from the file and break it down by words. C#
Create a text file, write the text to a C file#
Create an HTML file, write tabular data in an HTML file | C#
Create a binary file, write bytes to file C#
Partial upload of a file from FTP to C#
Class Path. Combine method - merges the strings into the full path of the file. And other methods of the Path class | C#
Serialization
What is object serialization in C#? [Serializable] attribute
Serializing a C# object into a binary file. BinaryFormatter class. [Serializable] attribute
Serializing a C# object into an XML file. XmlSerializer class. [Serializable] attribute
Serialization of a C# object into a JSON file. DataContractJsonSerializer class. [Serializable] attribute
Serializing a C# object into a SOAP file. SoapFormatter class. [Serializable] attribute
Namespaces
Namespace using in C#
Delegate
Delegate in C#
Add method(s) in a C# delegate. Unification of delegates. Removing a Method from a Delegate
Delegate as a parameter in method C#
Unnamed, anonymous method in C# (method described in place of parameter, delegate)
Universal Delegates
Generic, generic delegates in C# (templates)
Action, Predicate, and Func Universal Delegates in C#
Events
Events in C#
Lyamda
Lamda (example) in C#
Regular expressions
Regular Expressions in C#
Breaking the text into words (regular expressions in c#)
Put * instead of the last name after the first letter (regular expressions in c#)
Breaking the text into words (regular expressions in c#)
Process, process modules
Process in C# (Process class)
Process modules in C# (ProcessModule class)
Threads, multithreading
Threads in C# (Thread class)
Thread Pool in C#
What"s the difference between background and foreground in C#?
Synchronizing Threads in C#
Parallel Library Task (TPL)
Parallel Library Task (TPL). Parallel Task Library in C#
The Parallel class uses the Invoke method to execute the for and foreach (on different CPU cores) methods in parallel in C#
PLINQ parallelizes LINQ queries to run on different processor cores in C#
Asynchronous methods (async and await)
class Task in C#
Asynchronous programming in C# (async, await how to formalize)
Asynchronous programming in C# (using async, await, and Task as an example)
Asynchronous Programming in C# (Theory)
Application domains
What are Application Domains in C# ? (AppDomain class)
Example "Application domain information" (current domain name, list assemblies) in C#
Example "Let"s create the 2nd application domain. Write the class in the 1st domain and use it in the 2nd domain. MarshalByRefObject in C#
Example "Load the 2nd domain of the application from a file, run the calculations, unload the 2nd domain from memory" to C#
Attributes
Attributes for Class, Method, Property in C#
Attribute [Conditional("AAA")] . For compilation, ignore a method or property unless a conditional compilation symbol is defined in C#
Attribute [Obsolete("My method is outdated. Do not use", false)] Warning when compiling code in the C#
The [Display(Name="Sleep at night")] attribute. To store some text attached to a variable | C#
The attribute [Required(ErrorMessage = "Please enter a name")] is described for a property in the C# class and requires the property to be populated if the ErrorMessage error in the MVC ASP.NET is not filled in the screen
The attribute [Remote("IsValidAuthor", "Home", ErrorMessage = "Enter correct author of book")] is described for a property in a C# class and checks that property for correctness on the server via the IsValidAuthor method in conroller Home, if the method returns false, then there will be an ErrorMessage error on the screen in the MVC ASP.NET
Reflection in C#
Nameof operator in C# (class name, method name, variable name)
What is reflection in C#? Type Class
Creating a class object and calling the constructor with parameters using reflection in C#
How to get attribute information for a method from a class. Using reflection | C#
How to get attribute information for a property of a class. Using reflection | C#
How to change the set property in a class if private using reflection | C#
Preprocessor directives (if on compilation)
#define #undef #if #elif #else #endif preprocessor directives in C#
How do I define #define for all files (for the entire project) in C#?
What is the CLR assembly and runtime?
Assembly (Assembly) in C#. Compilation. Intermediate code IL (Intermediate Language). Metadata.
How to include a C# assembly in a project?
Utility ildasm.exe. Converts an assembly (C# exe, dll file) to an intermediate language (IL). This utility is easy to learn
The runtime CLR (Common Language Runtime) in C# . JIT (Just-In-Time) compiler.
Creating and connecting our build
Creating our C# build (regular build)
Connecting our C# build (regular build)
Creating our C# assembly (split assembly)
Connecting our C# assembly (split assembly)
Database in Console Application C#
Entity Framework in a C# console application. Using Code First (we write c# code, and the tables in the database are created by ourselves)
Read the image from the database and save it to a file | ADO.NET, C#, console application
DI Dependency Injection in C#
Dependency injection in C# | Dependency Injection (DI)
Ninject (IoC container) dependency management in C#
Autofac (IoC container) dependency management in C#
Convenient Visual Studio utilities
View Class Diagram in C#
exe to C# code
"dotPeek" application for decompile (disassemble) exe to c# source code
In a C# application, call the C++ functions
What are managed code (managed code) and unmanaged code (unmanaged code)? | C# and C++
Marshaling (marshalling) in C#. Type Conversion Between Managed Code (managed code) and Unmanaged Code (unmanaged code)
In the application C# we call functions from Windows dll (C++ WinAPI). Attribute [DllImport("user32.dll")]
In a C# application, call functions from my dll (C++). Attribute [DllImport("My.dll", CallingConvention = CallingConvention.Cdecl)]
Additional topics, questions
You don"t create a new project in Visual Studio 2019. Object reference not set to instance of an object"
C# compilation error: error CS1106: Extension method must be defined in a non-generic static class
C# compilation error: error CS0246: The type or namespace name "Point" could not be found (are you missing a using directive or an assembly reference?)
Why can"t the Dictionary.TryGetValue method find a value by key in C#?
Object-oriented programming (OOP). OOP Principles: Abstraction, Encapsulation, Inheritance, Polymorphism
What letters in C# (uppercase or lowercase or uppercase) should we use to name fields, methods in a class, interfaces, delegates, parameters?
Is it correct to create a separate .cs file for each class in C#? Or write C# classes in a single .cs file?
Is it better to use a built-in int type or an Integer class (string type or String class) in C#?
How do I download and install the version of the .NET Framework I want in Visual Studio?
Boxing and unboxing meaningful types in C#
Error CS8107 Feature "default literal" is not available in C# 7.0. Please use language version 7.1 or greater
Error "unable to connect to web server "iis express" | C# | Visual Studio 2017
Uninstall and install NuGet in Visual Studio
When opening a project in Visual Studio 2019 error: "project requires "SQL Server 2012 Express LocalDB" which is not installed on this computer"
The checked and unchecked math operators
The unchecked math operator in C#
The checked math operator in C#
Additional C# classes
C# Random class
C# Structure Point
C# PointF structure
C# Size structure
C# SizeF structure
C# Rectangle Structure
C# RectangleF structure
It"s time
The amount of time that has elapsed since the system booted (in milliseconds). System.Environment.TickCount in C#
Encryption
Let"s encrypt the password and check it | C# console application
Excell
Reading an excel file in C# (console application)
WWW Sites to Learn C#
Websites to learn C#

  Ваши вопросы присылайте по почте: info@dir.by