spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to elegantly search an array of struct in C#, porting from C++?


1) Use auto properties, and use a class for SPeriodInfo (class and struct have very different semantics in C#)

class SPeriodInfo
{
    public string   strItem   { get; private set;
}
    public int      nItemData { get; private set;
}
    public float    fPeriod   { get; private set;
}

    public SPeriodInfo(string item, int itemData,
float period)
    {
        strItem = item;
        nItemData = itemData;
        fPeriod = period;
    }
}

2) Don't use a hand-written loop to search for the period, you can use Array.Find or Linq :

float fPeriod = Array.Find(PeriodInfo,
    element => element.nItemData ==
slmRecordData.m_Settings.m_nSamplePeriod);

Or

float fPeriod =
PeriodInfo.FirstOrDefault(p=>p.nItemData ==
slmRecordData.m_Settings.m_nSamplePeriod).fPeri‌​od;

Categories : C#

Related to : How to elegantly search an array of struct in C#, porting from C++?
How to initialize a struct containing an array in Rust?
Rust does not implement Default for all arrays because it does not have non-type polymorphism, as such Default is only implementable for a handful of sizes. You can, however, implement a default for your type: impl Default for Histogram { fn default() -> Histogram { Histogram { sum: 0, bins: [0u32, ..256], } } } Note: I would contend that impl

Categories : Arrays
Initialize a 2d array inside a struct
Create a temporary struct and assign it to your element of the array of structs: struct block temp = { { {0, 1, 0}, {0, 1, 0}, {0, 1, 0} } } ; blockArray[0] = temp ; or just use your array and copy it: int temp[3][3] = { {0, 1, 0}, {0, 1, 0}, {0, 1, 0} } ; assert( sizeof( temp ) == sizeof( blockArray[0].theblock ) ) ; memcpy( blockArray[0].theblock , temp , sizeof( temp ) ) ;

Categories : C
ARM assembly : Access array elements residing in C type struct
A pointer is not the same thing as an array. f1 and f2 are 4 byte pointers in the struct. f3 is a 16-byte array in the struct. The struct as a whole is 24 bytes long. What you are loading into r10 is the first element of f3. If you want to set r10 to &f3[0], then just set r10 to r0 + P_STRUCT_F3.

Categories : C
Trouble porting C++ code to Rust
See This One Weird Trick To Beat The Borrow Checker: Compilers Hate It. #[deriving(Eq, PartialEq, Show, Clone)] struct Trie { eow: bool, val: char, chd: Vec<Trie> } impl Trie { fn new(eow: bool, val: char, chd: Vec<Trie>) -> Trie { Trie{eow: eow, val: val, chd: chd} } fn push_word(&mut self, word: &String) { let mut trie = self;

Categories : Rust
Const struct assigned to struct
It is not the same. You are trying to assign const pointer to a non const pointer. Another words: trying to assign Mutable pointer to a constant StudentType to a non-const pointer. It does make sense to change something that is declared const to no-cont, meaning you could change a value of a constant. What you are trying to do is to copy one object to another using shallow copy. in order to do so

Categories : Visual C++
Recently Add
Process MainWindowTitle not displaying for all running processes
SendGrid Tutorial resulting in Bad Request
Dropdown list from table in ASP NET MVC
Newtonsoft.JSON Serialization Array, Object, or Null
Using LINQ to select a byte array
How to stop scripting?
C# access to object property after json decode
How to kill instance of Word/Excel File in C#
Datatypes for MemoryStream.Capacity vs MemoryStream.Length
How to remove a selected row from a table when using KnockoutJS
SqlCommand returns null even tho there is data in the database
Replacing words in a body of text from array
C# dropping milliseconds from Java SOAP call
C# Deserialize list in JSON
Deserialize xml by linq, default with many elements
How to Access Grid View from hub section Data Template Windows phone 8.1 in C#
Input dialogue popup on mouse click
WPF: Binding to MainWindow Property SOLVED
Why is setting a field many times slower than getting a field?
Change multiple materials in one GameObject in Unity3D
.NET MVC error client side with custom validation attribute
Windows Search Service - text saved in ansi (codepage 1251) format - search for non-english symbols gives no result
String.Split - Omit empty array elements OR below a certain length
RequiredFieldValidator does not validate when ValidationGroup applied
Which WCF's extension point should be used for setting context for each operation?
Determine var type depending on ternary (?) Operator on int array
Resolving Windows phone 8.1 Compilation Error: GetENumerator
Specific Ordering of a List of Objects using LINQ
'string' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'string' could be found
how can ı pass data from serverside to clientside
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.