![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decimal.Negate() Method in C#
The Decimal.Negate() method in C# is used to return the result of multiplying the specified Decimal value by negative one.
Syntax
Following is the syntax −
public static decimal Negate (decimal val);
Above, Val is the value to negate.
Example
Let us now see an example to implement the Decimal.Negate() method −
using System; public class Demo { public static void Main(){ Decimal val = 3972.491M; Console.WriteLine("Decimal Value = {0}", val); Console.WriteLine("HashCode = {0}", (val.GetHashCode()) ); TypeCode type = val.GetTypeCode(); Console.WriteLine("TypeCode = "+type); Decimal res = Decimal.Negate(val); Console.WriteLine("Negative (Decimal) = "+res); } }
Output
This will produce the following output −
Decimal Value = 3972.491 HashCode = 620041307 TypeCode = Decimal Negative (Decimal) = -3972.491
Example
Let us now see another example to implement the Decimal.Negate() method −
using System; public class Demo { public static void Main(){ Decimal val = -29.35m; Console.WriteLine("Decimal Value = {0}", val); Console.WriteLine("HashCode = {0}", (val.GetHashCode()) ); TypeCode type = val.GetTypeCode(); Console.WriteLine("TypeCode = "+type); Decimal res = Decimal.Negate(val); Console.WriteLine("Negative (Decimal) = "+res); } }
Output
This will produce the following output −
Decimal Value = -29.35 HashCode = 1503969289 TypeCode = Decimal Negative (Decimal) = 29.35
Advertisements