472,325 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 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 2318
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...
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:...
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...
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 ...
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...
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...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.