728x90

The System namespace is the core namespace in the .NET framework, providing fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions. Here's an overview of some of the key classes and their purposes:

Key Classes:

  1. Object:
    • The root of the class hierarchy. Every class in C# directly or indirectly derives from this class.
    • Example methods: Equals(), GetHashCode(), ToString().
  2. String:
    • Represents text as a series of Unicode characters.
    • Example methods: Substring(), Replace(), IndexOf(), ToUpper(), ToLower().
    • Example:
      string greeting = "Hello, World!";
      string upperGreeting = greeting.ToUpper();
  3. Array:
    • Provides methods for creating, manipulating, searching, and sorting arrays.
    • Example methods: Sort(), Copy(), Clear().
    • Example:
      int[] numbers = { 1, 2, 3, 4, 5 };
      Array.Reverse(numbers);
  4. Console:
    • Represents the standard input, output, and error streams for console applications.
    • Example methods: WriteLine(), ReadLine().
    • Example:
      Console.WriteLine("Enter your name:");
      string name = Console.ReadLine();
      Console.WriteLine("Hello, " + name);
  5. Math:
    • Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
    • Example methods: Abs(), Ceiling(), Floor(), Pow(), Sqrt().
    • Example:
      double result = Math.Sqrt(25);
  6. DateTime:
    • Represents an instant in time, typically expressed as a date and time of day.
    • Example methods: Now, Today, AddDays(), ToString().
    • Example:
      DateTime now = DateTime.Now;
      Console.WriteLine("Current Date and Time: " + now);
  7. Random:
    • Represents a pseudo-random number generator, which is a device that produces a sequence of numbers that meet certain statistical requirements for randomness.
    • Example methods: Next(), NextDouble(), NextBytes().
    • Example:
      Random random = new Random();
      int randomNumber = random.Next(1, 100);

Example Usage:

Here's a simple example demonstrating the use of some of these classes:

using System;

class Program
{
    static void Main()
    {
        // Using the String class
        string greeting = "Hello, World!";
        string upperGreeting = greeting.ToUpper();
        Console.WriteLine(upperGreeting);

        // Using the Array class
        int[] numbers = { 1, 2, 3, 4, 5 };
        Array.Reverse(numbers);
        Console.WriteLine("Reversed Array: " + string.Join(", ", numbers));

        // Using the DateTime class
        DateTime now = DateTime.Now;
        Console.WriteLine("Current Date and Time: " + now);

        // Using the Math class
        double result = Math.Sqrt(25);
        Console.WriteLine("Square Root of 25: " + result);

        // Using the Random class
        Random random = new Random();
        int randomNumber = random.Next(1, 100);
        Console.WriteLine("Random Number: " + randomNumber);
    }
}
728x90
반응형

'Software > C#' 카테고리의 다른 글

C# 시작하기 - 날짜형 변환  (0) 2025.01.21
C# DevExpress - WinForm GridControl Header 90회전  (1) 2025.01.20
C# 시작하기 - DirectoryInfo  (0) 2025.01.11
C# 시작하기 - FileInfo  (0) 2025.01.11
C# 시작하기 - System.IO  (0) 2025.01.11

+ Recent posts