IRONSOFTWAREHOME
.NET HELP

In C# (How It Works For Developers)

Jacob Mellor, Chief Technology Officer @ Team Iron
Jacob Mellor
Updated: April 23, 2026

C# is a powerful, type-safe programming language that offers developers a rich set of features for building complex applications. At the heart of many programming tasks are operators - the building blocks that allow us to perform operations on variables and values. This article dives into various types of operators such as arithmetic operators, focusing on their precedence, usage, and the introduction of some new features that enhance the language's capabilities. We'll also cover the IronPDF library as a comprehensive .NET PDF tool for .NET applications.

Arithmetic Operators

Arithmetic operators, essential in any programming language for numeric manipulation, perform operations such as addition, subtraction, multiplication, and division among others on numeric operands. This section covers each operator's name, description, and provides examples to illustrate their use in C#.

Operator Name, Description, Example

For instance, consider the basic arithmetic operations:

  • Addition (+): Adds two operands. Example: int x = 5 + 3;
  • Subtraction (-): Subtracts the right-hand operand or value from the left-hand operand. Example: int y = x - 2;
  • Multiplication (*): Multiplies two operands. Example: int z = x * y;
  • Division (/): Divides the left-hand operand/variable by the right-hand operand. Example: int d = z / 2;

These are straightforward, with the operands being the values or variables involved in the operation, such as x, y, and z in the examples above.

Numeric Negation

An interesting unary arithmetic operator is numeric negation (-), which reverses the sign of a numeric operand. For example, if we have int x = 5;, then -x would result in -5.

Binary Operators and Operator Precedence

Binary operators, denoted as "op" in expressions like x op y, require two operands to perform their operations. For instance, in x + y, "+" is the binary operator, with x and y as its operands. Understanding operator precedence is crucial for accurately evaluating expressions with multiple operators.

Understanding Operator Precedence with an Example

Consider the following example: int result = 3 + 4 * 2;. Here, the multiplication operation has higher precedence than addition, so 4 * 2 is evaluated first, followed by adding 3 to the result, yielding 11.

The Null Coalescing Operator

A notable new feature in C# is the null coalescing operator (??), which provides a concise way to check for null values. This operator returns the left-hand operand if it is not null; otherwise, it returns the right-hand operand as shown in the following example.

Example

class Program
{
    static void Main(string[] args)
    {
        int? x = null; // nullable int, initialized to null
        int y = x ?? -1; // using null coalescing operator to provide a default value
        Console.WriteLine("The value of y is: " + y); // outputs: The value of y is: -1
    }
}

In this example, y would be -1 because x is null. The null coalescing operator simplifies checks for null values, especially when working with nullable types.

In C# (How It Works For Developers): Figure 1 - Null Coalescing Operator Name Description Example Output

New Features: The Null Coalescing Assignment Operator

C# has added a feature called the null coalescing assignment operator, symbolized by ??=. This operator checks if the variable on its left side is null. If it is, the operator assigns the value from the right side to the left side variable form.

Demonstrating Null Coalescing Assignment Expression

int? a = null; // nullable int, initialized to null
a ??= 10; // Assigns 10 to a since it is null

Here, a would be 10 after the operation because it was initially null. This operator streamlines code by reducing the need for explicit null checks and assignments.

Advanced Operations: Lambda Declaration and Type Testing

Lambda declarations and type testing are more advanced features that leverage operators for concise and powerful functionality.

Lambda Declaration Example

Lambda expressions in C# use the lambda operator (=>) to create inline functions. For instance:

Func<int, int, int> add = (x, y) => x + y; // Lambda function to add two integers
int sum = add(5, 3); // Calls the lambda expression with 5 and 3, returns 8

This code snippet defines a simple function to add two integer values using a lambda expression.

Type Testing with the 'is' Operator

Type testing is performed using the is operator, allowing you to check the type at runtime. For example:

object obj = "Hello World"; // obj is a string
if (obj is string s) {
    Console.WriteLine(s); // Outputs: Hello World
}

This checks if obj is of type string and assigns it to s if true.

In C# (How It Works For Developers): Figure 2 - is Operator Output

Working with PDFs in C#: An Introduction to IronPDF

In C# (How It Works For Developers): Figure 3 - IronPDF

When dealing with document generation and manipulation in C#, managing PDF files is a common requirement. IronPDF stands out as a comprehensive library designed to enable developers to create PDFs from HTML with IronPDF, and read, and edit PDF documents directly within .NET applications without needing any dependency. This section explores how IronPDF can be integrated into C# projects, especially focusing on operations related to our earlier discussion on operators and variables.

Installing IronPDF

Before diving into the capabilities of IronPDF, the first step is to integrate the library into your project. IronPDF can be easily added via NuGet, a popular package manager for .NET. By using the NuGet Package Manager, you can include IronPDF in your project with minimal effort.

To install IronPDF, you can use the Package Manager Console command:

PM > Install-Package IronPdf

Alternatively, you can use the NuGet Package Manager UI in Visual Studio by searching for "IronPDF" and installing it directly into your project.

Example: Generating a PDF Document with Arithmetic Operations

Once IronPDF is added to your project, you can start utilizing its features to generate and manipulate PDF documents. Here's a simple example demonstrating how to create a PDF document that includes the result of arithmetic operations, tying back to our discussion on operators.

using IronPdf;

public class PdfGenerationExample
{
    public static void CreatePdfWithArithmeticOperations()
    {
        // Create a new PDF document
        var pdf = new HtmlToPdf();
        // HTML content with embedded C# arithmetic
        var htmlContent = @"
            <html>
                <body>
                    <h1>Arithmetic Operations Result</h1>
                    <p>Result of 3 + 4: " + (3 + 4).ToString() + @"</p>
                    <p>Result of 10 * 2: " + (10 * 2).ToString() + @"</p>
                    <p>Result of 50 / 5: " + (50 / 5).ToString() + @"</p>
                </body>
            </html>";

        // Convert HTML to PDF
        var document = pdf.RenderHtmlAsPdf(htmlContent);
        // Save the PDF to a file
        document.SaveAs("ArithmeticOperations.pdf");
    }
}

In this example, we create a simple HTML template that includes the results of various arithmetic operations, similar to what we discussed earlier. IronPDF renders this HTML content into a PDF document, showcasing how seamlessly C# code and HTML can be combined to generate dynamic documents.

In C# (How It Works For Developers): Figure 4 - Arithmetic Operations Output

Conclusion

Operators in C# are essential for performing various kinds of operations, from basic arithmetic to complex type testing and lambda expressions. Understanding these operators, their precedence, and how to use them effectively is crucial for any developer looking to master C#. IronPDF offers a free trial for developers to explore its features and capabilities. Should you decide to integrate it into your production environment, licensing starts from $999. With the introduction of new features like the null coalescing assignment operator, C# continues to evolve, offering more efficient and concise ways to write code.

Jacob Mellor, Chief Technology Officer @ Team Iron
Chief Technology Officer

Jacob Mellor is Chief Technology Officer at Iron Software and a visionary engineer pioneering C# PDF technology. As the original developer behind Iron Software's core codebase, he has shaped the company's product architecture since its inception, transforming it alongside CEO Cameron Rimington into a 50+ person company serving NASA, Tesla, and global government agencies.

...
Read More

Related Articles

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999