473,372 Members | 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,372 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 1208
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: Phl 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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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?
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...

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.