473,386 Members | 1,803 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,386 software developers and data experts.

C# equivalent syntax

Hi all
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance.

double *firstVal;
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;
Nov 15 '05 #1
10 1422
Are we glad C# does not have those pointers! Anyways, that code does not make much sense

Tu-Thac

----- C# newcomer wrote: ----

Hi al
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance

double *firstVal;
int secondVal
double thirdVal
int fourthVal

firstVal = new double[secondVal]
*(firstVal + thirdVal) = fourthVal

delete [] firstVal

Nov 15 '05 #2
C# newcomer <an*******@discussions.microsoft.com> wrote:
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance.

double *firstVal;
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;


Converting bare syntax is rarely a good idea, especially in thise case
where there isn't necessarily an equivalent. Instead, tell us what
you're trying to do and we can tell you what idiom is usually used in
C#.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Hi C# newcomer,
Welcome to C# :)
double *firstVal; you can't use pointers anymore. You have to use indeces to access items int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;
int firstVal;
int secondVal;
double thirdVal;
int fourthVal;

//I assume all valrirables are initialized
firstVal = 0;
double[] doubleArray = new double[secondVal];
doubleArray[firstVal + thirdVal] = fourthVal;

Pay attention that the firstVal is index rather than pointer. This could
affect your program logic.

--
B\rgds
100
"C# newcomer" <an*******@discussions.microsoft.com> wrote in message
news:6e****************************@phx.gbl... Hi all
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance.

double *firstVal;
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;

Nov 15 '05 #4
This is code snippet, I believe, and it makes sense as so.

--
B\rgds
100
"Tu-Thach" <an*******@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Are we glad C# does not have those pointers! Anyways, that code does not make much sense.
Tu-Thach

----- C# newcomer wrote: -----

Hi all
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance.

double *firstVal;
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;

Nov 15 '05 #5
You either have to cast thirdVal to an int or declare it as an int otherwise this code will not work

Tu-Thac

----- Stoitcho Goutsev (100) [C# MVP] wrote: ----

Hi C# newcomer
Welcome to C# :
double *firstVal you can't use pointers anymore. You have to use indeces to access item int secondVal
double thirdVal
int fourthVal
firstVal = new double[secondVal] *(firstVal + thirdVal) = fourthVal
delete [] firstVal


int firstVal
int secondVal
double thirdVal
int fourthVal

//I assume all valrirables are initialize
firstVal = 0
double[] doubleArray = new double[secondVal]
doubleArray[firstVal + thirdVal] = fourthVal

Pay attention that the firstVal is index rather than pointer. This coul
affect your program logic

--
B\rgd
10
"C# newcomer" <an*******@discussions.microsoft.com> wrote in messag
news:6e****************************@phx.gbl.. Hi al
Please help me with the C# equivalent syntax for th
following C++ code. Thanks a lot in advance
double *firstVal

int secondVal
double thirdVal
int fourthVal
firstVal = new double[secondVal]

*(firstVal + thirdVal) = fourthVal
delete [] firstVal


Nov 15 '05 #6

"Tu-Thach" <an*******@discussions.microsoft.com> schreef in bericht
news:93**********************************@microsof t.com...
Are we glad C# does not have those pointers! Anyways, that code does not make much sense.
Tu-Thach


I'm glad it still has those pointers when you really need them ...

Yves
Nov 15 '05 #7
Oh, yes, sorry. I think it is and error in the original post and I missted
it.
Actually, I believe C# newcommer wanted to write
int thirdVal;
and
double fourtVal;.

Anyways I believe the question was prety clear, since it wasn't
what-is-wrong-with-my-code one.
--
B\rgds
100
"Tu-Thach" <tu*****@ongtech.com> wrote in message
news:89**********************************@microsof t.com...
You either have to cast thirdVal to an int or declare it as an int otherwise this code will not work.
Tu-Thach

----- Stoitcho Goutsev (100) [C# MVP] wrote: -----

Hi C# newcomer,
Welcome to C# :)
> double *firstVal; you can't use pointers anymore. You have to use indeces to access

items
> int secondVal;
> double thirdVal;
> int fourthVal;
>> firstVal = new double[secondVal];

> *(firstVal + thirdVal) = fourthVal;
>> delete [] firstVal;


int firstVal;
int secondVal;
double thirdVal;
int fourthVal;

//I assume all valrirables are initialized
firstVal = 0;
double[] doubleArray = new double[secondVal];
doubleArray[firstVal + thirdVal] = fourthVal;

Pay attention that the firstVal is index rather than pointer. This

could affect your program logic.

--
B\rgds
100
"C# newcomer" <an*******@discussions.microsoft.com> wrote in message
news:6e****************************@phx.gbl...
> Hi all
> Please help me with the C# equivalent syntax for the
> following C++ code. Thanks a lot in advance.
>> double *firstVal;

> int secondVal;
> double thirdVal;
> int fourthVal;
>> firstVal = new double[secondVal];

> *(firstVal + thirdVal) = fourthVal;
>> delete [] firstVal;


Nov 15 '05 #8
double firstVal[];
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
firstVal[thirdVal] = fourthVal;

"C# newcomer" <an*******@discussions.microsoft.com> wrote in message
news:6e****************************@phx.gbl...
Hi all
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance.

double *firstVal;
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;

Nov 15 '05 #9
double[] firstVal;
int secondVal;
double thirdVal;
int fourthVal;

// secondVal, thirdVal and fourthVal must be set before the following lines,
otherwise the C# compiler will reject them.
firstVal = new double[secondVal];
// C++ version of following line would also benefit from the rewriting
below!
firstVal[(int)thirdVal] = fourthVal;
// no need to delete array, GC does it!

Morale: C# just forces you to write something that make sense (from a type
checking standpoint). You can forget about ugly pointer hacks (like
*(firstVal + thirdVal) -- does C++ really accept this without barking, seems
to me that an (int) cast would be necessary on thirdVal)

Bruno.

"C# newcomer" <an*******@discussions.microsoft.com> a écrit dans le message
de news:6e****************************@phx.gbl...
Hi all
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance.

double *firstVal;
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;

Nov 15 '05 #10
Hi Ken,
As long as it is a code snipped and we don't actually know how the code,
which simplification we have, works
lines like
*(firstVal + thirdVal) = fourthVal;

Makes me believe that the array is indexed changing both firstVal and
thirdVal
otherwise it would be
firstVal[thirdVal] = fourthVal;

That's way I believe we should keep virstVal as an index to the array and
have one separate array object

--
B\rgds
100
"Ken Onweller (.NET MCSD)" <an*******@discussions.microsoft.com> wrote in
message news:ex**************@TK2MSFTNGP09.phx.gbl...
double firstVal[];
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
firstVal[thirdVal] = fourthVal;

"C# newcomer" <an*******@discussions.microsoft.com> wrote in message
news:6e****************************@phx.gbl...
Hi all
Please help me with the C# equivalent syntax for the
following C++ code. Thanks a lot in advance.

double *firstVal;
int secondVal;
double thirdVal;
int fourthVal;

firstVal = new double[secondVal];
*(firstVal + thirdVal) = fourthVal;

delete [] firstVal;


Nov 15 '05 #11

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

Similar topics

1
by: JBBHF | last post by:
Hi i'm working on a web project, and i would like to make my oracle query work in mysql. select match.numero "nummatch", to_char(match.datematch, 'yyyy-MM-dd') "datematch", p1.numjoueur "j1",...
3
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an...
7
by: Old Wolf | last post by:
I often see it written here that the declaration T t = a; (where 'a' is not of type T) calls the copy-constructor and is exactly equivalent to T t(( T(a) )); However the following code gives...
7
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s :...
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
9
by: Paul Brownjohn | last post by:
Hello I am new both to this group and to C# programming having spent the last 15 years or so writing C and VB. You will forgive I hope if I am asking the totally obvious but it is a question...
8
by: Xucyr | last post by:
I can't find any "short" code to make this work without taking 100s of lines (because I have to keep repeating this process several times). But this is what I have so far: int i = 7; do {...
11
by: gnuist006 | last post by:
Is there a Delphi equivalent in the C world or Scheme/LISP world ? Recently, Delphi is in resurgence. In Russia people are using like crazy. For example, Bolega has written a free image...
5
by: Richard | last post by:
I'm just getting my feet wet in DB2 UDB (9.x), after years as a Sybase DBA. In Sybase, if I wanted to delete data from one table based on joining that table to a second table, I'd use this syntax...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.