Main. Abs method in C#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Aravind GovindarajRank #430 · 5.8K reputationPosted Oct 25, 2022, 10:51 AM EDT
This is used to return a positive value of the specified number. Please find the reference link for the same
https://www.alphacodingskills.com/cs/notes/cs-math-abs.php
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 27, 2022, 10:54 AM EDT
The Math.Abs() method in C# is used to return the absolute value of a specified number in C#. This specified number can be decimal, double, 16-bit signed integer, etc.
Example
using System; class Demo { public static void Main(){ Double val1 = 30.40; Double val2 = Double.MinValue; Double val3 = Double.MaxValue; Console.WriteLine("Absolute value of {0} : {1}", val1, Math.Abs(val1)); Console.WriteLine("Absolute value of {0} : {1}", val2, Math.Abs(val2)); Console.WriteLine("Absolute value of {0} : {1}", val3, Math.Abs(val3)); } }