C# is a strongly-typed language. It means we must declare the type of a variable that indicates the kind of values it is going to store, such as integer, float, decimal, text, etc. Show The following declares and initialized variables of different data types.
C# mainly categorized data types in two types: Value types and Reference types. Value types include simple types (such as int, float, bool, and char), enum types, struct types, and Nullable value types. Reference types include class types, interface types, delegate types, and array types. Learn about value types and reference types in detail in the next chapter. Predefined Data Types in C#C# includes some predefined value types and reference types. The following table lists predefined data types:
As you can see in the above table that each data type (except string and object) includes value range. The compiler will give an error if the value goes out of datatype's permitted range. For example, int data type's range is -2,147,483,648 to 2,147,483,647. So if you assign a value which is not in this range, then the compiler would give an error.
The value of unsigned integers, long, float, double, and decimal type must be suffix by u,l,f,d, and m, respectively.
Alias vs .NET TypeThe predefined data types are alias to their .NET type (CLR class) name. The following table lists alias for predefined data types and related .NET class name.
It means that whether you define a variable of
Default ValuesEvery data type has a default value. Numeric type is 0, boolean has false, and char has
ConversionsThe values of certain data types are automatically converted to different data types in C#. This is called an implicit conversion.
In the above example, the value of an integer variable The following is an implicit data type conversion table.
Conversions from int, uint, long, or ulong to float and from long or ulong to double may cause a loss of precision. No data type implicitly converted to the char type. However, not all data types are implicitly converted to other data types. For example, int type cannot be converted to uint implicitly. It must be specified explicitly, as shown below.
In the above example, integer Which of the following is not correct about a data type?This is Expert Verified Answer
The answer to the question is option A)"real" which is not a correct data type.
Which of the following data types holds only true and false values?Boolean (bool)
It represents the values true and false. When working with the boolean data type, it is helpful to keep in mind that sometimes a boolean value is also represented as 0 (for false) and 1 (for true).
Which of the following statements best describes a form?1 Answer. (a) The form enables people to enter or view data in a database easily.
Which of the following is not a data type in C#?arr is not a data type. Boolean is a data type that is used to declare a statement either true or false. Character is a data type that is used to declare alphabets in both uppercase and lowercase. Int is a data type that is used to declare integers.
|