470,620 Members | 1,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,620 developers. It's quick & easy.

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 1143
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by _R | last post: by
4 posts views Thread by PŚhl Melin | last post: by
9 posts views Thread by Edward Diener | last post: by
5 posts views Thread by news.chi.sbcglobal.net | last post: by
5 posts views Thread by =?Utf-8?B?U2hhaWxlbiBTdWt1bA==?= | last post: by
5 posts views Thread by Bruce | last post: by
4 posts views Thread by ajk | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.