عرض مشاركة واحدة
  #4  
قديم 11-03-2010, 10:38 PM
سليم سلامة سليم سلامة غير متواجد حالياً
عضو جديد
 
تاريخ التسجيل: Mar 2010
المشاركات: 33
معدل تقييم المستوى: 0
سليم سلامة is on a distinguished road
افتراضي

اقتباس:
المشاركة الأصلية كتبت بواسطة kinghero مشاهدة المشاركة
أريد معرفة لماذا لا يمكن تحويل النوع single & double الي النوع Decimal بالتحويل المباشر مع العلم بأن single & double سعتهم التخزنية أقل من الـ Decimal
هذا كان رد أ/ سيف على إجابة السؤال
ان عملية التحويل بين الانواع المختلفة قد شغل الجميع
وقد احتار الكل
كيف لا يمكن التحويل من double و single الى decimal بالرغم من ان الاخير هو الاكبر ( 16 Byte ) و 29 خانة

لازالة الحيرة

التحويل المباشر و الغير مباشر


widening conversion

narrowing conversion

implicit conversion

explicit conversion

الكلمات الاربع السابقة هي المفتاح

وطبعا الترجمة

الواسع

الضيق

الضمني

الصريح

ان كتاب المدرسة قد خلط بين الكلمات
كيف ؟ سنوضح ذلك

بالرجوع الةى msdn
وجد الاتي

A widening conversion changes
a value to a data type that can accommodate any possible value of the original data.


A narrowing conversion changes
a value to a data type that might not be able to hold some of the possible values.

An implicit conversion does not require any special syntax in the source code. In the following example, Visual Basic implicitly converts the value of k to a single-precision floating-point value before assigning it to q.


Dim k As Integer
Dim q As Double
' Integer widens to Double, so you can do this with Option Strict On.
k = 432
q = K



An explicit conversion uses a type conversion keyword. Visual Basic provides several such keywords, which coerce an expression in parentheses to the desired data type. These keywords act like functions, but the compiler generates the code inline, so execution is slightly faster than with a function call.


مما سبق نلاحظ ان

التحويل ليس بين الانواع
ولكن بين القيم

كما ان المباشر هو من لا يحتاج الى كلمات او دوال
والغير مباشر هو الذي يعتمد على كلمات ودوال للتحويل


بالرجول الي القيم نجد ان اكبر القيم هي قيم double

For +ve values approximately 4.9*10-324
to
1.8*(10)
+308
For -ve values approximately -1.8*10+308
to -
4.9*(10)
-324
And 0

ويليها في الصغر single

For +ve values approximately1.4*(10)
-45
to
3.4*(10)
+38
For -ve values approximately -3.4*(10)
+38
to
1.4*(10)
-45
And 0

ثم decimal

ثم long ثم integer ثم short

وعليه الحيرة ان كتاب المدرسي قد ذكر ان التحويل بين الانواع

والحقيقة انه بين القيم التى يمكن تخزينها في تلك الانواع