array-initialize

How to set array length in c# dynamically

元气小坏坏 提交于 2019-12-30 02:37:06
问题 I am still new to C# and I've been struggling with various issues on arrays. I've got an array of metadata objects (name value pairs) and I would like to know how to create only the number of "InputProperty" objects that I truly need. In this loop I've arbitrarily set the number of elements to 20 and I try to bail out when the entry becomes null but the web service on the receiving end of this does not like any null elements passed to it: private Update BuildMetaData(MetaData[] nvPairs) {

How to initialize two-dimensional arrays in Fortran

我怕爱的太早我们不能终老 提交于 2019-12-17 05:03:09
问题 In C you can easily initialize an array using the curly braces syntax, if I remember correctly: int* a = new int[] { 1, 2, 3, 4 }; How can you do the same in Fortran for two-dimensional arrays when you wish to initialize a matrix with specific test values for mathematical purposes? (Without having to doubly index every element on separate statements) The array is either defined by real, dimension(3, 3) :: a or real, dimension(:), allocatable :: a 回答1: You can do that using reshape and shape

initialize a const array in a class initializer in C++

自古美人都是妖i 提交于 2019-12-17 02:13:12
问题 I have the following class in C++: class a { const int b[2]; // other stuff follows // and here's the constructor a(void); } The question is, how do I initialize b in the initialization list, given that I can't initialize it inside the body of the function of the constructor, because b is const ? This doesn't work: a::a(void) : b([2,3]) { // other initialization stuff } Edit: The case in point is when I can have different values for b for different instances, but the values are known to be

How do you initialize a 2 dimensional array when you do not know the size

99封情书 提交于 2019-12-10 03:18:52
问题 I have a two dimensional array that I need to load data into. I know the width of the data (22 values) but I do not know the height (estimated around 4000 records, but variable). I have it declared as follows: float[,] _calibrationSet; .... int calibrationRow = 0; While (recordsToRead) { for (int i = 0; i < SensorCount; i++) { _calibrationSet[calibrationRow, i] = calibrationArrayView.ReadFloat(); } calibrationRow++; } This causes a NullReferenceException, so when I try to initialize it like

How do you initialize a 2 dimensional array when you do not know the size

て烟熏妆下的殇ゞ 提交于 2019-12-05 03:57:18
I have a two dimensional array that I need to load data into. I know the width of the data (22 values) but I do not know the height (estimated around 4000 records, but variable). I have it declared as follows: float[,] _calibrationSet; .... int calibrationRow = 0; While (recordsToRead) { for (int i = 0; i < SensorCount; i++) { _calibrationSet[calibrationRow, i] = calibrationArrayView.ReadFloat(); } calibrationRow++; } This causes a NullReferenceException, so when I try to initialize it like this: _calibrationSet = new float[,]; I get an "Array creation must have array size or array initializer

How to set array length in c# dynamically

雨燕双飞 提交于 2019-11-30 08:20:35
I am still new to C# and I've been struggling with various issues on arrays. I've got an array of metadata objects (name value pairs) and I would like to know how to create only the number of "InputProperty" objects that I truly need. In this loop I've arbitrarily set the number of elements to 20 and I try to bail out when the entry becomes null but the web service on the receiving end of this does not like any null elements passed to it: private Update BuildMetaData(MetaData[] nvPairs) { Update update = new Update(); InputProperty[] ip = new InputProperty[20]; // how to make this "dynamic"

How do you initialise a const array of TGUID from Interface type data, in Delphi?

北城以北 提交于 2019-11-29 10:25:11
I want to initialise an array like this - Const MyArray : Array[0..0] Of TGUID = (IInterface); But it results in - [DCC Error] Test.pas(10): E2010 Incompatible types: 'TGUID' and 'string' So to see what would happen I tried this - Const MyArray : Array[0..0] Of String = (IInterface); Which results in this! [DCC Error] Test.pas(10): E2010 Incompatible types: 'string' and 'TGUID' How strange! Surely IInterface is one or the other, but it seems to stubbornly transform into the wrong type. You can pull the GUIDs from the interface declarations and declare them as (string) constants. You can then

How do you initialise a const array of TGUID from Interface type data, in Delphi?

核能气质少年 提交于 2019-11-28 00:31:51
问题 I want to initialise an array like this - Const MyArray : Array[0..0] Of TGUID = (IInterface); But it results in - [DCC Error] Test.pas(10): E2010 Incompatible types: 'TGUID' and 'string' So to see what would happen I tried this - Const MyArray : Array[0..0] Of String = (IInterface); Which results in this! [DCC Error] Test.pas(10): E2010 Incompatible types: 'string' and 'TGUID' How strange! Surely IInterface is one or the other, but it seems to stubbornly transform into the wrong type. 回答1:

Array initialization with default constructor

烈酒焚心 提交于 2019-11-27 08:53:18
public class Sample { static int count = 0; public int abc; public Sample() { abc = ++Sample.count; } } I want to create an array of above class, and want each element in the array to be initialized by invoking the default constructor, so that each element can have different abc .So I did this: Sample[] samples = new Sample[100]; But this doesn't do what I think it should do. It seems this way the default constructor is not getting called. How to invoke default constructor when creating an array? I also would like to know what does the above statement do? You can't, basically. When you create

How to initialize two-dimensional arrays in Fortran

假装没事ソ 提交于 2019-11-27 01:00:42
In C you can easily initialize an array using the curly braces syntax, if I remember correctly: int* a = new int[] { 1, 2, 3, 4 }; How can you do the same in Fortran for two-dimensional arrays when you wish to initialize a matrix with specific test values for mathematical purposes? (Without having to doubly index every element on separate statements) The array is either defined by real, dimension(3, 3) :: a or real, dimension(:), allocatable :: a Wildcat You can do that using reshape and shape intrinsics. Something like: INTEGER, DIMENSION(3, 3) :: array array = reshape((/ 1, 2, 3, 4, 5, 6, 7,