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

Conversion C#->CLI (snippets)

Thanks to everyone who has helped with some of my elementary questions about
C++/CLI equivalents to C#. I have a few more items that are giving me
headaches. All help is appreciated. What is the proper way to convert the
following?

1) data.ForEach(delegate(int num)
{ formatter->Serialize(stream, num); } );

(basically how are delegates implemented in C++/CLI)

2) return result as Dictionary<string, int>;

(how is this dynamic_cast performed?)

3) How do I pass an "array<int>^ myArray" into a method that takes an
integer array as an argument? Do I just pass the first element of the array,
like so: myArray[0]?

Thanks again for all the help
Karch
Nov 17 '05 #1
7 1209
The anonymous method C# style for delegates does not exist in C++.

About passing the array, just pass "myArray": e.g., SomeMethod(myArray)

Download the demo edition of our new Instant C++ C# to C++ converter at
www.tangiblesoftwaresolutions.com

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
Thanks to everyone who has helped with some of my elementary questions about
C++/CLI equivalents to C#. I have a few more items that are giving me
headaches. All help is appreciated. What is the proper way to convert the
following?

1) data.ForEach(delegate(int num)
{ formatter->Serialize(stream, num); } );

(basically how are delegates implemented in C++/CLI)

2) return result as Dictionary<string, int>;

(how is this dynamic_cast performed?)

3) How do I pass an "array<int>^ myArray" into a method that takes an
integer array as an argument? Do I just pass the first element of the array,
like so: myArray[0]?

Thanks again for all the help
Karch

Nov 17 '05 #2
David,

OK, I tried your demo tool - it gave me the following for one of the
conversions.

generic<typename String^, typename int>
Dictionary^ MethodA()
{
Object^ result;
return dynamic_cast<Dictionary^>(result)<String^, int>;
}

This give me errors: syntax error for the '^' in the first line and
'unexpected tokens preceding {'. What am I doing wrong?
"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
The anonymous method C# style for delegates does not exist in C++.

About passing the array, just pass "myArray": e.g., SomeMethod(myArray)

Download the demo edition of our new Instant C++ C# to C++ converter at
www.tangiblesoftwaresolutions.com

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
Thanks to everyone who has helped with some of my elementary questions
about
C++/CLI equivalents to C#. I have a few more items that are giving me
headaches. All help is appreciated. What is the proper way to convert the
following?

1) data.ForEach(delegate(int num)
{ formatter->Serialize(stream, num); } );

(basically how are delegates implemented in C++/CLI)

2) return result as Dictionary<string, int>;

(how is this dynamic_cast performed?)

3) How do I pass an "array<int>^ myArray" into a method that takes an
integer array as an argument? Do I just pass the first element of the
array,
like so: myArray[0]?

Thanks again for all the help
Karch

Nov 17 '05 #3
Please post the original C# code. Is the original code compilable?

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
David,

OK, I tried your demo tool - it gave me the following for one of the
conversions.

generic<typename String^, typename int>
Dictionary^ MethodA()
{
Object^ result;
return dynamic_cast<Dictionary^>(result)<String^, int>;
}

This give me errors: syntax error for the '^' in the first line and
'unexpected tokens preceding {'. What am I doing wrong?
"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
The anonymous method C# style for delegates does not exist in C++.

About passing the array, just pass "myArray": e.g., SomeMethod(myArray)

Download the demo edition of our new Instant C++ C# to C++ converter at
www.tangiblesoftwaresolutions.com

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
Thanks to everyone who has helped with some of my elementary questions
about
C++/CLI equivalents to C#. I have a few more items that are giving me
headaches. All help is appreciated. What is the proper way to convert the
following?

1) data.ForEach(delegate(int num)
{ formatter->Serialize(stream, num); } );

(basically how are delegates implemented in C++/CLI)

2) return result as Dictionary<string, int>;

(how is this dynamic_cast performed?)

3) How do I pass an "array<int>^ myArray" into a method that takes an
integer array as an argument? Do I just pass the first element of the
array,
like so: myArray[0]?

Thanks again for all the help
Karch


Nov 17 '05 #4
This is the original C# code, and yes it compiles:

Dictionary<string, int> MyMethod()
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();

object result = formatter.Deserialize(stream);
return result as Dictionary<string, int>;
}

"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
Please post the original C# code. Is the original code compilable?

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
David,

OK, I tried your demo tool - it gave me the following for one of the
conversions.

generic<typename String^, typename int>
Dictionary^ MethodA()
{
Object^ result;
return dynamic_cast<Dictionary^>(result)<String^, int>;
}

This give me errors: syntax error for the '^' in the first line and
'unexpected tokens preceding {'. What am I doing wrong?
"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
> The anonymous method C# style for delegates does not exist in C++.
>
> About passing the array, just pass "myArray": e.g., SomeMethod(myArray)
>
> Download the demo edition of our new Instant C++ C# to C++ converter at
> www.tangiblesoftwaresolutions.com
>
> --
> David Anton
> www.tangiblesoftwaresolutions.com
> Instant C#: VB.NET to C# Converter
> Instant VB: C# to VB.NET Converter
> Instant C++: C# to C++ Converter
> Instant J#: VB.NET to J# Converter
>
>
>
> "karch" wrote:
>
>> Thanks to everyone who has helped with some of my elementary questions
>> about
>> C++/CLI equivalents to C#. I have a few more items that are giving me
>> headaches. All help is appreciated. What is the proper way to convert
>> the
>> following?
>>
>> 1) data.ForEach(delegate(int num)
>> { formatter->Serialize(stream, num); } );
>>
>> (basically how are delegates implemented in C++/CLI)
>>
>> 2) return result as Dictionary<string, int>;
>>
>> (how is this dynamic_cast performed?)
>>
>> 3) How do I pass an "array<int>^ myArray" into a method that takes an
>> integer array as an argument? Do I just pass the first element of the
>> array,
>> like so: myArray[0]?
>>
>> Thanks again for all the help
>> Karch
>>
>>
>>


Nov 17 '05 #5
We've confirmed that the following two areas are converted incorrectly:
1. Generic method return types
2. "as" used with generic types

We are correcting this now - I'll post a follow-up when the new build is
available.

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
This is the original C# code, and yes it compiles:

Dictionary<string, int> MyMethod()
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();

object result = formatter.Deserialize(stream);
return result as Dictionary<string, int>;
}

"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
Please post the original C# code. Is the original code compilable?

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
David,

OK, I tried your demo tool - it gave me the following for one of the
conversions.

generic<typename String^, typename int>
Dictionary^ MethodA()
{
Object^ result;
return dynamic_cast<Dictionary^>(result)<String^, int>;
}

This give me errors: syntax error for the '^' in the first line and
'unexpected tokens preceding {'. What am I doing wrong?
"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
> The anonymous method C# style for delegates does not exist in C++.
>
> About passing the array, just pass "myArray": e.g., SomeMethod(myArray)
>
> Download the demo edition of our new Instant C++ C# to C++ converter at
> www.tangiblesoftwaresolutions.com
>
> --
> David Anton
> www.tangiblesoftwaresolutions.com
> Instant C#: VB.NET to C# Converter
> Instant VB: C# to VB.NET Converter
> Instant C++: C# to C++ Converter
> Instant J#: VB.NET to J# Converter
>
>
>
> "karch" wrote:
>
>> Thanks to everyone who has helped with some of my elementary questions
>> about
>> C++/CLI equivalents to C#. I have a few more items that are giving me
>> headaches. All help is appreciated. What is the proper way to convert
>> the
>> following?
>>
>> 1) data.ForEach(delegate(int num)
>> { formatter->Serialize(stream, num); } );
>>
>> (basically how are delegates implemented in C++/CLI)
>>
>> 2) return result as Dictionary<string, int>;
>>
>> (how is this dynamic_cast performed?)
>>
>> 3) How do I pass an "array<int>^ myArray" into a method that takes an
>> integer array as an argument? Do I just pass the first element of the
>> array,
>> like so: myArray[0]?
>>
>> Thanks again for all the help
>> Karch
>>
>>
>>


Nov 17 '05 #6
Thanks David.

So, without waiting for a new build, what would the correct conversion of
the code be? I am trying to convert this now, so if you could post the
correct answer it would be of great help.

\K

"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
We've confirmed that the following two areas are converted incorrectly:
1. Generic method return types
2. "as" used with generic types

We are correcting this now - I'll post a follow-up when the new build is
available.

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
This is the original C# code, and yes it compiles:

Dictionary<string, int> MyMethod()
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();

object result = formatter.Deserialize(stream);
return result as Dictionary<string, int>;
}

"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
> Please post the original C# code. Is the original code compilable?
>
> --
> David Anton
> www.tangiblesoftwaresolutions.com
> Instant C#: VB.NET to C# Converter
> Instant VB: C# to VB.NET Converter
> Instant C++: C# to C++ Converter
> Instant J#: VB.NET to J# Converter
>
>
>
> "karch" wrote:
>
>> David,
>>
>> OK, I tried your demo tool - it gave me the following for one of the
>> conversions.
>>
>> generic<typename String^, typename int>
>> Dictionary^ MethodA()
>> {
>> Object^ result;
>> return dynamic_cast<Dictionary^>(result)<String^, int>;
>> }
>>
>> This give me errors: syntax error for the '^' in the first line and
>> 'unexpected tokens preceding {'. What am I doing wrong?
>>
>>
>> "David Anton" <Da********@discussions.microsoft.com> wrote in message
>> news:FF**********************************@microsof t.com...
>> > The anonymous method C# style for delegates does not exist in C++.
>> >
>> > About passing the array, just pass "myArray": e.g.,
>> > SomeMethod(myArray)
>> >
>> > Download the demo edition of our new Instant C++ C# to C++ converter
>> > at
>> > www.tangiblesoftwaresolutions.com
>> >
>> > --
>> > David Anton
>> > www.tangiblesoftwaresolutions.com
>> > Instant C#: VB.NET to C# Converter
>> > Instant VB: C# to VB.NET Converter
>> > Instant C++: C# to C++ Converter
>> > Instant J#: VB.NET to J# Converter
>> >
>> >
>> >
>> > "karch" wrote:
>> >
>> >> Thanks to everyone who has helped with some of my elementary
>> >> questions
>> >> about
>> >> C++/CLI equivalents to C#. I have a few more items that are giving
>> >> me
>> >> headaches. All help is appreciated. What is the proper way to
>> >> convert
>> >> the
>> >> following?
>> >>
>> >> 1) data.ForEach(delegate(int num)
>> >> { formatter->Serialize(stream, num); } );
>> >>
>> >> (basically how are delegates implemented in C++/CLI)
>> >>
>> >> 2) return result as Dictionary<string, int>;
>> >>
>> >> (how is this dynamic_cast performed?)
>> >>
>> >> 3) How do I pass an "array<int>^ myArray" into a method that takes
>> >> an
>> >> integer array as an argument? Do I just pass the first element of
>> >> the
>> >> array,
>> >> like so: myArray[0]?
>> >>
>> >> Thanks again for all the help
>> >> Karch
>> >>
>> >>
>> >>
>>
>>
>>


Nov 17 '05 #7
The new build is available. The bug affecting generic method return types and
"as" used with generic types is fixed.

The C++/CLI equivalent for your sample is:

Dictionary<String^, int> ^MyMethod()
{
BinaryFormatter ^formatter = gcnew BinaryFormatter();
MemoryStream ^stream = gcnew MemoryStream();

Object ^result = formatter->Deserialize(stream);
return dynamic_cast<Dictionary<String^, int>^>(result);
}

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
Thanks David.

So, without waiting for a new build, what would the correct conversion of
the code be? I am trying to convert this now, so if you could post the
correct answer it would be of great help.

\K

"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
We've confirmed that the following two areas are converted incorrectly:
1. Generic method return types
2. "as" used with generic types

We are correcting this now - I'll post a follow-up when the new build is
available.

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"karch" wrote:
This is the original C# code, and yes it compiles:

Dictionary<string, int> MyMethod()
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();

object result = formatter.Deserialize(stream);
return result as Dictionary<string, int>;
}

"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
> Please post the original C# code. Is the original code compilable?
>
> --
> David Anton
> www.tangiblesoftwaresolutions.com
> Instant C#: VB.NET to C# Converter
> Instant VB: C# to VB.NET Converter
> Instant C++: C# to C++ Converter
> Instant J#: VB.NET to J# Converter
>
>
>
> "karch" wrote:
>
>> David,
>>
>> OK, I tried your demo tool - it gave me the following for one of the
>> conversions.
>>
>> generic<typename String^, typename int>
>> Dictionary^ MethodA()
>> {
>> Object^ result;
>> return dynamic_cast<Dictionary^>(result)<String^, int>;
>> }
>>
>> This give me errors: syntax error for the '^' in the first line and
>> 'unexpected tokens preceding {'. What am I doing wrong?
>>
>>
>> "David Anton" <Da********@discussions.microsoft.com> wrote in message
>> news:FF**********************************@microsof t.com...
>> > The anonymous method C# style for delegates does not exist in C++.
>> >
>> > About passing the array, just pass "myArray": e.g.,
>> > SomeMethod(myArray)
>> >
>> > Download the demo edition of our new Instant C++ C# to C++ converter
>> > at
>> > www.tangiblesoftwaresolutions.com
>> >
>> > --
>> > David Anton
>> > www.tangiblesoftwaresolutions.com
>> > Instant C#: VB.NET to C# Converter
>> > Instant VB: C# to VB.NET Converter
>> > Instant C++: C# to C++ Converter
>> > Instant J#: VB.NET to J# Converter
>> >
>> >
>> >
>> > "karch" wrote:
>> >
>> >> Thanks to everyone who has helped with some of my elementary
>> >> questions
>> >> about
>> >> C++/CLI equivalents to C#. I have a few more items that are giving
>> >> me
>> >> headaches. All help is appreciated. What is the proper way to
>> >> convert
>> >> the
>> >> following?
>> >>
>> >> 1) data.ForEach(delegate(int num)
>> >> { formatter->Serialize(stream, num); } );
>> >>
>> >> (basically how are delegates implemented in C++/CLI)
>> >>
>> >> 2) return result as Dictionary<string, int>;
>> >>
>> >> (how is this dynamic_cast performed?)
>> >>
>> >> 3) How do I pass an "array<int>^ myArray" into a method that takes
>> >> an
>> >> integer array as an argument? Do I just pass the first element of
>> >> the
>> >> array,
>> >> like so: myArray[0]?
>> >>
>> >> Thanks again for all the help
>> >> Karch
>> >>
>> >>
>> >>
>>
>>
>>


Nov 17 '05 #8

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

Similar topics

3
by: _R | last post by:
Any late-breaking updates on C++/CLI docs or books? I've been waiting for Lippman's book, listed as published in September, but it looks like it's not available. My primary project is...
3
by: nan | last post by:
Hi All, I am trying to connect the Database which is installed in AS400 using DB2 Client Version 8 in Windows box. First i created the Catalog, then when i selected the connection type...
4
by: Påhl Melin | last post by:
I have some problems using conversion operators in C++/CLI. In my project I have two ref class:es Signal and SignalMask and I have an conversion function in Signal to convert Signal:s to...
5
by: Lonewolf | last post by:
Hi, I'm not sure if this has been asked before so please pardon me if this is a repeated question. Basically I have some performance critical directshow codes which is implemented in native,...
9
by: Edward Diener | last post by:
Are there any differences between the version of C++/CLI as implemented in Visual C++ 2005 and the ECMA-372 C++/CLI Language Specification of December 2005 freely downloaded from ECMA ? Asking...
5
by: news.chi.sbcglobal.net | last post by:
I have a question about string literals with C++/CLI. Is there a difference between the following two lines? String ^s1 = gcnew String("Hello"); String ^s2 = gcnew String(L"Hello"); I have...
5
by: =?Utf-8?B?U2hhaWxlbiBTdWt1bA==?= | last post by:
I have some code that was written in managed C++ using VS 2005. I want to convert that code into C#. Is there a tool available to do this? Thanks in advance. -- Shailen Sukul Architect (BSc...
5
by: Bruce | last post by:
I have some code in MC++. I would like to convert it to CLI. Is there a conversion program that exists anywhere? If so where? Bruce
4
by: ajk | last post by:
Hi Given an array of bytes i.e. cli::array<Byte>^ar I would like convert from and to a structure/class What is the best way to do this in C++/CLI ? I have looked at using a union class A
4
by: Ty | last post by:
Hello all, I am creating a website in VS 2008 VB.net. On one of my pages I am using the Table control to make a type of calendar a IN/OUT board. The problem I found after I wrote all the code...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.