AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 17.12.2015, 12:02   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
mfp: X++ in AX7: Const keyword
Источник: http://blogs.msdn.com/b/mfp/archive/...t-keyword.aspx
==============
In AX7 X++ now supports the const keyword. Semantically it is identical to const in C#.

In short; it allows you to define members on a class and variables in a method that can only be initialized during the declaration. The compiler will replace references to these constants with the literal value. In other words, the constant value must be known at compile time.

This is a killer feature! It replaces most use cases of macros.

void constsAreCool()
{
#define.magicNumber("AX 2012");
const str magicNumber = "AX7";
info(#magicNumber);
info(magicNumber);
}





There are many benefits:

  1. IntelliSense in the editor.
  2. Support for "Go to definition" in the editor.
  3. Full control of the type for the constant.
  4. Faster compilation – macros are notorious hard for the compiler to handle.
  5. None of the macro idiosyncrasies – like the ability to redefine/override.
Now when you couple this with public and static members, then you can create classes with constants to replace macro libraries.

static class TimeConstants
{
static const public int DaysPerWeek = 7;
static const public int HoursPerDay = 24;
static const public int HoursPerWeek = TimeConstants::DaysPerWeek * TimeConstants::HoursPerDay;
}


Notice how the constants in the class are referenced:

TimeConstants::HoursPerWeek

This is much clearer than macros:

#TimeConstants
int x = #HoursPerWeek


For example; you are no longer in doubt where the definition is coming from.



THIS POST APPLIES TO MICROSOFT DYNAMICS AX7 TECHNICAL PREVIEW; IS PROVIDED AS-IS AND CONFERS NO RIGHTS.




==============
Источник: http://blogs.msdn.com/b/mfp/archive/...t-keyword.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
ax7

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
mfp: X++ in AX7: Internal keyword Blog bot DAX Blogs 25 20.12.2015 19:36
mfp: X++ in AX7: Readonly keyword Blog bot DAX Blogs 3 15.12.2015 18:22
mfp: X++ in AX7: Static event subscription Blog bot DAX Blogs 0 11.12.2015 11:11
mfp: X++ in AX7: The var keyword Blog bot DAX Blogs 43 04.12.2015 10:19
mfp: X++ in AX7 Blog bot DAX Blogs 0 02.12.2015 22:13
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 09:19.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.