473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

array of struct

Mel
I am translating C++ to C# coding. I have given array of struct in C++, is
there any good alternatives for "array of struct" in c#? I hope anyone can
help. Thank you very much.
Nov 23 '05 #1
6 2371
Hi,

Mel wrote:
I am translating C++ to C# coding. I have given array of
struct in C++, is there any good alternatives for "array
of struct" in c#?


There is nothing that prevents you from having just that -- an array of
struct -- in C#, in case you were under impression that couldn't be done.

If you are asking whether there is a better way, then an excerpt from the
original C++ code would be helpful.

--
Chris Priede
Nov 23 '05 #2
MyStruct[] structArray = new MyStruct[] {mystruct1, mystruct2, ....};

--is this what you are referring to? You could use an ArrayList, a Hashtable,
-- it all depends what the business logic is that you want.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mel" wrote:
I am translating C++ to C# coding. I have given array of struct in C++, is
there any good alternatives for "array of struct" in c#? I hope anyone can
help. Thank you very much.

Nov 23 '05 #3
Mel
Hi,

Thanks for your reply. I want to implement list of struct.

using System;
using System.Text;
using System.Xml;
using System.IO;
using System.Collections;
using System.Collections.Generic;
public class MrcPunct
{
public struct PunctSf
{
public char code;
public string punct;
public PunctSf(char co, string pun)
{
code = co;
punct = pun;
}
}

public List<PunctSf> sf100 = new List<PunctSf>{new PunctSf('b', ","),new
PunctSf('c', ",")};
}

Can you tell me what's wrong in this code? I can't even get it compile.
When I compile, I got this error.

"A new expression requires () or [] after type"

in this line
public List<PunctSf> sf100 = new List<PunctSf>{new PunctSf('b', ","),new
PunctSf('c', ",")};

I hope anyone can give me suggestion. thank you very much.

Mel

"Mel" wrote:
I am translating C++ to C# coding. I have given array of struct in C++, is
there any good alternatives for "array of struct" in c#? I hope anyone can
help. Thank you very much.

Nov 23 '05 #4
An array is not the same as a generic list. You cannot use { } when you
instantiate a list.

Nov 23 '05 #5
Mel
Hi Alex,

How can I declare the struct list in the same time I can initialise it?

Hope you can answer my question. Thank you

Mel

"Alexander Kolliopoulos" wrote:
An array is not the same as a generic list. You cannot use { } when you
instantiate a list.

Nov 23 '05 #6
Mel wrote:
Hi Alex,

How can I declare the struct list in the same time I can initialise it?

<snip>

List<PunctSf> sf100 = new List<PunctSf>(
new PunctSf[] {
new PunctSf('b', ","),
new PunctSf('c', ",")
});

Untested but should work. Note that this will construct an array first,
then provide that array to the List<T> constructor to use for
initializing the list with.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Nov 24 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
10
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr;...
6
by: Eric Smith | last post by:
Is a structure containing an incomplete array as its last element (per paragraph 2 of section 6.7.2.1 of ISO/IEC 9899:1999 (E)) itself an incomplete type? That appears to be indicated by paragraph...
10
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
5
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and...
7
by: Sam | last post by:
Hello I have a structure called Company. struct Company { char *employee; char *employee_address; }; I want to build an array of this structure but the number of employees will change...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
20
by: Cyn | last post by:
Hi, I want to create a general array structure which can hold all types. Something like this: struct ARRAY { void **array; size_t size; };
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
6
by: npankey | last post by:
I've started experimenting with template metaprogramming in a small project of mine. What I'm trying to accomplish is to generate a static array of templated objects that get specialized based on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.