Tammam Koujan

Welcome to my world

Archive for the ‘C#’ Category

أوبس!! هل حقا ما أراه؟

Posted by tammamkoujan on July 29, 2007

أوبس!! هل حقا ما أراه؟

بسم الله الرحمن الرحيم

موضوعنا اليوم سيكون مختلفا قليلا عن المواضيع التي طرحتها سابقا فلن أتحدث عن إنشاء مكون أو أداة برمجية أو عن مشروع معين حديثي اليوم سيكون بعض الأمور التي ليس من المتوقع ان تحدث عند كتابة اي برنامج لكنها تحدث و قد يتعجب بعض المبرمجين من سبب حدوثها.
في الحالة الأولى أنظر معي للشيفرة التالية:

for (float i = 0.5f; i < 1; i += 0.01f)
{
if (i == 0.6f)
{
Console.WriteLine(i);
}
}

في مقطع الشيفرة السابق أنشأت حلقة for و عرفت فيها المتحول i من النوع float و مهدته بالقيمة 0.5 و جعلت مقدار الزيادة على المتحول i في كل مرة تساوي 0.01 اي واحد بالمئة و جعلت الحلقة مستمرة طالما المتحول i اصغر من القيمة 1
حسنا كل شيء حتى الان طبيعي و صحيح
وضعت ضمن كتلة الحلقة عبارة if تقوم بطباعة قيمة المتحول i على الشاشة عندما تبلغ هذه القيمة 0.6
تبعا للشرح المنطقي السابق ستتوقع ان كل شيء صحيح و انه نتيجة تنفيذ مقطع الشيفرة السابق ستكون طباعة قيمة المتحول i عندما يصبح 0.6
اسف لان اخيب املك و اقول لك بأن شيئا لن يحدث و لن تطبع قيمة المتحول i ابدا
و للتأكد من هذا الامر قم بنسخ الشيفرة السابقة و ضعها في مشروع جديد و قم بالتنفيذ .
بعد أن تأكدنا من هذاالكلام دعنا نفسر ما الذي حدث و كيف نتجاوز هذه المشكلة
تكمن المشكلة السابقة في تعريفنا للمتحول i على انه من النوع float و الأنواع الخاصة بالفاصلة العائمة مثل float تتعامل مع الارقام و تجعلها تقوم بالعمليات الحسابية بطريقة خاصة و تحتفظ بقيمة تقريبية للناتج
للتأكد من هذا الكلام قم بتجربة الشيفرة التالية:

for (float i = 0.5f; i < 1; i += 0.01f)
{
Console.WriteLine(i);
}

سيكون الناتج كما في الصورة أدناه:

cmd.jpg

أمر مدهش أليس كذلك
لو بحثت عن القيمة 0.6 التي كنا نستخدمها في عبارة if من أجل المقارنة فلن تجدها
اذن فالمتحول i لن يحتوي على القيمة 0.6 في أي حال من الاحوال
ما هو الحل لهذه المشكلة ؟ حسنا كما اخبرتكم سابقا بسبب الطبيعة الخاصة للتعامل مع الاعداد ذات الفاصلة العائمة فسيتم تخزين قيمة تقريبية للعدد و ليس العدد نفسه لذا يمكن ان نعتبر ان المتحول i وصل للقيمة 0.6 عندما تكون قيمته قريبة جدا منها
لذا سنتستخدم الشيفرة التالية و التي ستعمل بشكل صحيح معنا:

for (float i = 0.5f; i < 1; i += 0.01f)
{
if ((i > 0.59f)&&(i < 0.6f))
{
Console.WriteLine(“0.6″);
}
}

نلتقي في الجزء الثاني مع حالة مدهشة جديدة

تمام كوجان في 29/07/2007
ُEmail : TammamKoujan@Gmail.com
يجوز نشر هذه المقالة أو أجزاء منها بشرط المحافظة على اسم الكاتب و ذكر المصدر

Posted in C#, برمجة | 4 Comments »

الجديد من ميكروسوفت

Posted by tammamkoujan on July 22, 2007

الجديد من ميكروسوفت

وصلتني رسالة إلكترونية من ميكروسوفت تتحدث عن موعد الطرح النهائي للمنتجات الجديدة للشركة
و اضع بين ايديكم الجزء الرئيسي من الرسالة و قد ترجمت القسم الاول منها نظرا لأهميته:

شباط (فبراير) سيصل أسرع مما تعتقد:

لماذا هو الامر مهم ان تنتظر منتصف الشتاء و أنت ما زلت في منتصف الصيف؟ الجواب هو ان شهر شباط (فبراير) 2008 سيكون مختلفا كونه سيكون شهر ميكروسوفت الذي ستطرح فيه أكبر عدد من منتجاتها المهمة على الإطلاق ذلك من خلال نسخ RTM من Visual Studio 2008 و Windows Server 2008 و SQL Server 2008 .
و يمكن أن تبدأ بالتحضير من الان. فالاصدار القادم من فيجوال ستوديو Microsoft Visual Studio 2008 (و المعروف بالاسم الكودي “Orcas” ) سيوفر للمطورين اختبار Windows Vista و كذلك نظام Microsoft Office 2007 إضافة إلى الويب
و لتوفر إمكانية الاختبار و التجريب المبكر فقد وفرت ميكروسوفت إصدارات Community Technology Preview (CTP) و Beta
من Visual Studio 2008

February will arrive sooner than you think.

Why is it so important to consider the middle of winter in the middle of summer? Because February 2008 is shaping up to be Microsoft’s largest launch month – ever – with RTMs of Visual Studio 2008, Windows Server 2008, and SQL Server 2008 all on tap. And you can begin preparing now. The next version of Visual Studio, Microsoft Visual Studio 2008 (formerly known as Microsoft Visual Studio code name “Orcas”), will provide a developer experience for Windows Vista, the 2007 Microsoft Office system, and the Web. To enable early feedback, Microsoft provides Community Technology Preview (CTP) and Beta releases of Visual Studio 2008. Get an early look at Visual Studio 2008 Beta 1 and check back for the late-summer Beta 2 release.

If you create software development tools, you’ll want to consider building on the Visual Studio 2008 Shell, a streamlined Visual Studio development environment that provides the core foundation so you can focus on building your tool’s unique features. Created in response to requests from our partners, the Visual Studio Shell gives you the option of integrating your tools with Visual Studio or creating an isolated, custom-branded application.

If you are building on the new features in the .NET Framework 3.0, such as Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), and Windows CardSpace, you’ll want to preview the The .NET Framework 3.5 Beta 1 release, which will ship with Visual Studio 2008. .NET Framework 3.5 adds several new features, including integration of Language Integrated Query (LINQ); ASP.NET AJAX; new Web protocol support for building WCF services including AJAX, JSON, REST, POX, RSS, and ATOM; full tooling support for WF, WCF, and WPF; and new classes in the base class library (BCL).

Speaking of ASP.NET, MSDN is now offering the ASP.NET “How Do I” video series, with dozens of videos designed for all ASP.NET developers, from the novice to the professional. If you are new to ASP.NET, you can learn the basics of how to create dynamic Web applications with ASP.NET 2.0 and Visual Web Developer 2005 Express Edition, using either Visual Basic or C#. If you have a bit of development experience, you will learn how to employ some of the great new features introduced in ASP.NET 2.0. New videos are added every week, so check back often.

And here’s a learning tip that comes with free stuff. Register to attend an MSDN Event near you from August through September in one of dozens of U.S. locations, and you’ll receive a copy of the MSDN Events Technical Resource Kit, which includes access to the latest builds of new technologies, including Visual Studio 2008, a sample Silverlight application (with source code), free trials of Microsoft Expression suite products, Visual Web Developer 2005, and more.
Thanks for reading.
Editor, MSDN Flash

Posted in C Sharp, C#, SQL Server, برمجة, تكنولوجيا | 4 Comments »