是否可以声明一个包含另一个常量数组的常量数组? [英] Is it possible do Declare a constant array that includes another constant array?

查看:98
本文介绍了是否可以声明一个包含另一个常量数组的常量数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

const

  MyFirstConstArray: array[0..1] of string = ('Hi', 'Foo');
  MySecondConstArrayWhichIncludesTheFirstOne: array[0..2] of string = 
    MyFirstConstArray + ('Bar');

基本上我想要以下结果:

Basically I want the following result:

MyFirstConstArray -> ('Hi', 'Foo');
MySecondConstArrayWhichIncludesTheFirstOne -> ('Hi', 'Foo', 'Bar');

有可能吗?

推荐答案

AFAIK,您不能这样做。

但是,如果目标是确保只声明一次实际的常量字符串,建议您声明各个字符串,然后将它们分组为数组:

AFAIK, you can't do that.
But if the goal is to ensure you declare your actual constant string only once, I suggest you declare the individual strings and then group them in arrays:

const
  MyConst1 = 'Hi';
  MyConst2 = 'Foo';
  MyConst3 = 'Bar';
  MyFirstConstArray: array[0..1] of string = (MyConst1, MyConst2);
  MySecondConstArrayWhichIncludesTheFirstOne: array[0..2] of string = 
    (MyConst1, MyConst2, MyConst3);

BTW,您的语法不正确,必须精确调整数组元素的类型。

BTW, your syntax is incorrect, you have to precise the type of the array elements.

这篇关于是否可以声明一个包含另一个常量数组的常量数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆