BaseUnit Struct
Definition
Represents a base unit of measurement, including its category, name, and symbol.
Examples
Represent a unit of measurement with its category, name, and symbol. This example creates several BaseUnit instances, demonstrates property access, and shows how to compare units for equality to verify that units with identical properties are considered equal:
using System;
using Codebelt.Unitify;
namespace Unitify.Samples;
public class BaseUnitExample
{
public static void Main()
{
// Create a meter base unit
var meter = new BaseUnit("Length", "Meter", "m");
Console.WriteLine($"Category: {meter.Category}");
Console.WriteLine($"Name: {meter.Name}");
Console.WriteLine($"Symbol: {meter.Symbol}");
// Create a kilogram base unit
var kilogram = new BaseUnit("Mass", "Kilogram", "kg");
// Compare base units
var sameUnit = new BaseUnit("Length", "Meter", "m");
Console.WriteLine($"meter == sameUnit: {meter == sameUnit}");
}
}
public readonly struct BaseUnit : IBaseUnit, IEquatable<IBaseUnit>
- Implements
- Inherited Members
Constructors
| Name | Description |
|---|---|
| BaseUnit(string, string, string) | Initializes a new instance of the BaseUnit class. |
Properties
| Name | Description |
|---|---|
| Category | Gets the category of the base unit. |
| Name | Gets the name of the base unit. |
| Symbol | Gets the symbol of the base unit. |
Methods
| Name | Description |
|---|---|
| Equals(IBaseUnit) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object) | Determines whether the specified object is equal to the current object. |
| GetHashCode() | Returns a hash code for this instance. |
Operators
| Name | Description |
|---|---|
| operator ==(BaseUnit, BaseUnit) | Determines whether two specified instances of BaseUnit are equal. |
| operator !=(BaseUnit, BaseUnit) | Determines whether two specified instances of BaseUnit are not equal. |