IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C# Programming - Datatypes - Discussion

@ : Home > C# Programming > Datatypes > General Questions - Discussion

Read more:

"To err is human; to forgive, divine."
- Alexander Pope
1. 

Which of the following statements are correct about data types?

  1. If the integer literal exceeds the range of byte, a compilation error will occur.
  2. We cannot implicitly convert non-literal numeric types of larger storage size to byte.
  3. Byte cannot be implicitly converted to float.
  4. A char can be implicitly converted to only int data type.
  5. We can cast the integral character codes.

[A]. 1, 3, 5
[B]. 2, 4
[C]. 3, 5
[D]. 1, 2, 5

Answer: Option D

Explanation:

No answer description available for this question.


Sundar said: (Thu, Feb 2, 2012 10:32:08 AM)    
 
There is a predefined implicit conversion from byte to short, ushort, int, uint, long, ulong, float, double, or decimal.

You cannot implicitly convert nonliteral numeric types of larger storage size to byte. Consider, for example, the following two byte variables x and y:

byte x = 10, y = 20;

The following assignment statement will produce a compilation error, because the arithmetic expression on the right-hand side of the assignment operator evaluates to int by default.

byte z = x + y; // Error: conversion from int to byte

To fix this problem, use a cast:

byte z = (byte)(x + y); // OK: explicit conversion

It is possible though to use the following statements, where the destination variable has the same storage size or a larger storage size:

int x = 10, y = 20;
int m = x + y;
long n = x + y;

Also, there is no implicit conversion from floating-point types to byte. For example, the following statement generates a compiler error unless an explicit cast is used:

byte x = 3.0; // Error: no implicit conversion from double
byte y = (byte)3.0; // OK: explicit conversion

When calling overloaded methods, a cast must be used. Consider, for example, the following overloaded methods that use byte and int parameters:

public static void MyMethod(int i) {}
public static void MyMethod(byte b) {}
Using the byte cast guarantees that the correct type is called, for example:

MyMethod(5); // Calling the method with the int parameter
MyMethod((byte)5); // Calling the method with the byte parameter

Source:
http://msdn.microsoft.com/en-us/library/5bdb6693(v=vs.71).aspx

Hope this will help you. Have a nice day!

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!