System.Runtime Namespace

Provides fundamental types and base classes that are used throughout the .NET Framework and .NET. This namespace includes types for primitive data types, object identity, exception handling, and basic runtime operations.

Object Class

Provides functionality common to all classes, serving as the ultimate base class of the .NET object hierarchy.

public abstract class Object

Remarks

The Object class is the root of the .NET object hierarchy. All types in the .NET Framework are derived, directly or indirectly, from Object.

Exception Class

Represents errors that occur during application execution.

public abstract class Exception : System.Object, System.Runtime.Serialization.ISerializable

Remarks

The Exception class is the base class for all exceptions. All exceptions thrown by the .NET Framework or by applications are derived from Exception.

Exceptions

  • ArgumentNullException: If the specified null reference exception is null.
  • ArgumentOutOfRangeException: If the specified argument is out of the allowed range of values.

Example


try
{
    // Code that might throw an exception
    int zero = 0;
    int result = 10 / zero;
}
catch (DivideByZeroException ex)
{
    Console.WriteLine($"An error occurred: {ex.Message}");
    // Handle the exception
}
finally
{
    Console.WriteLine("Execution finished.");
}
                        
ValueType Class

Represents value types, which are the base type for all value types in the .NET Framework.

public abstract class ValueType : System.Object

Remarks

Value types are types that contain data members directly, rather than containing references to objects. Primitive types such as System.Int32, System.Boolean, and System.Double are examples of value types.

String Class

Represents text as a sequence of characters.

public sealed class String : System.Object, System.IComparable, System.IComparable<string>, System.ICloneable, System.IConvertible, System.Collections.Generic.IEnumerable<char>, System.Collections.IEnumerable

Members

  • Length: Gets the number of characters in the current String object.
  • this[int index]: Gets the character at the specified position in the current String object.

Example


string message = "Hello, World!";
Console.WriteLine($"The message is: {message}");
Console.WriteLine($"Length: {message.Length}");
Console.WriteLine($"Character at index 0: {message[0]}");
                        
Int32 Struct

Represents a 32-bit signed integer.

public struct Int32 : System.IComparable, System.IComparable<int>, System.IConvertible, System.IFormattable

Remarks

The Int32 structure represents integers ranging from -2,147,483,648 to 2,147,483,647. This is the most commonly used integral type.

Example


int count = 100;
long bigNumber = count + 5000000000L;
Console.WriteLine($"Count: {count}");
Console.WriteLine($"Big Number: {bigNumber}");
                        
Boolean Struct

Represents a Boolean value (true or false).

public struct Boolean : System.IComparable, System.IComparable<bool>, System.IConvertible

Remarks

The Boolean structure is used to represent logical states. It can have only two possible values: true or false.

Example


bool isComplete = true;
if (isComplete)
{
    Console.WriteLine("Task is complete.");
}
else
{
    Console.WriteLine("Task is pending.");
}
                        
DateTime Struct

Represents an instance in time, expressed as a date and time of day.

public struct DateTime : System.IComparable, System.IComparable<System.DateTime>, System.IConvertible, System.IFormattable, System.Runtime.Serialization.ISerializable

Members

  • Now: Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
  • Today: Gets the current date, with the time component set to midnight (00:00:00).

Example


DateTime now = DateTime.Now;
Console.WriteLine($"Current Date and Time: {now}");
Console.WriteLine($"Current Date: {DateTime.Today.ToShortDateString()}");
                        
Console Class

Provides standard input, output, and error streams for console applications.

public static class Console

Members

  • WriteLine(string value): Writes the specified value, followed by the current line terminator, to the standard output stream.
  • ReadLine(): Reads the next line of characters from the standard input stream and returns as a string.
  • Error: Gets a TextWriter object that represents the standard error stream.

Example


Console.WriteLine("Enter your name:");
string name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");
                        
Math Class

Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.

public static class Math

Members

  • PI: Represents the ratio of the circumference of a circle to its diameter, approximately 3.14159.
  • Abs(double value): Returns the absolute value of a number.
  • Sqrt(double value): Returns the square root of a specified number.
  • Pow(double x, double y): Returns x raised to the power of y.

Example


double radius = 5.0;
double area = Math.PI * Math.Pow(radius, 2);
Console.WriteLine($"Area of circle with radius {radius}: {area}");