Using Modulus or % to get the Remainder in C#

Published on May 13, 2013 by abundantcode

Filed under C#

Last modified May 13, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 5562 times

Below is a sample soucrecode demonstrating how to get remainder in c# using Modulus or Remainder operator (%).

Using Modulus or % to get the Remainder in C#

using System;

namespace AbundantCode

{

internal class Program

{

//Using Modulus or % to get the Remainder in C#

private static void Main(string[] args)

{

int result;

double Input;

var output = 10 % 3;

Console.WriteLine("Remainder = " + output.ToString());

Console.ReadLine();

}

}

}

Using Modulus or % to get the Remainder in C#

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

1 Comment

  1. Nice, easy, simple tutorial with even simpler code to understand. Thank you.

    For those who are more curious, this article examines the fastest way to get the remainder between using modulus or an alternative with addition:
    http://blogs.davelozinski.com/curiousconsultant/csharp-net-use-the-modulus-operator-or-alternative

    It’s obviously more for speed and micro-optimization junkies.

    🙂

    _

    December 17, 2013 - 6:01 am – Reply

Leave a Comment


x

You might be Interested in these Posts

Using Null Coalescing Operator in C#

Sometimes , you may want to simply the Null checks in your .NET Program without much usage of the if...

Using or Operator in the Where Clause of LINQ in C#

Below is a sample code snippet demonstrating on how to use "Or" Operator in the Where Clause of Linq...

How to return Http Status Code from ASP.NET Web API Controller ?

There are times when you might want to return the Http Status code from an action method of a ASP.NE...