Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Type suffix for decimal

I don't know what the correct wording is for what I am trying to achieve so it may already be posted online. Please be kind if it is.

Ok so basically I have this method.

public static T IsNull<T>(IDataReader dr, String name, T nullValue) {     return Helpers.IsNull(dr, dr.GetOrdinal(name), nullValue); }  public static T IsNull<T>(IDataReader dr, Int32 index, T nullValue) {     if (dr.IsDBNull(index))     {         return nullValue;     }     else     {         return (T)dr.GetValue(index);     } } 

Being called as Helpers.IsNull(dr, "UnitWholeSale", 0d) and the error I am getting is "Cannot convert from double to decimal".

Now I know I can use decimal.Zero but is there some way that I can simply go 0dec or something similar? I just hate those long shortcut values (especially when you are calling a constructor with 20 parameters).

like image 339
Maxim Gershkovich Avatar asked Mar 17 '11 00:03

Maxim Gershkovich


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

How old is the letter C?

The letter c was applied by French orthographists in the 12th century to represent the sound ts in English, and this sound developed into the simpler sibilant s.


2 Answers

0m is how you say (decimal)0 because m is the suffix that means decimal.

Other suffixes are f for float, d for double, u for unsigned, and l for long. They can be either upper- or lower-case and u can be combined with l in either order to make a ulong.

Although the suffixes are not case-sensitive, keep in mind what it says in the C# language specification, section 2.4.4.2:

As a matter of style, it is suggested that “L” be used instead of “l” when writing literals of type long, since it is easy to confuse the letter “l” with the digit “1”.

like image 148
Gabe Avatar answered Oct 24 '22 20:10

Gabe


0m will give you a decimal 0 value.

For the sake of completeness,

0.0 - double 0f  - float 0m  - decimal 
like image 22
Adam Robinson Avatar answered Oct 24 '22 21:10

Adam Robinson