Conversion C#->CLI (snippets)

  • Thread starter Thread starter karch
  • Start date Start date
K

karch

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
 
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
 
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 said:
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 said:
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
 
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 said:
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 said:
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 said:
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
 
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 said:
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 said:
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 said:
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



:

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
 
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 said:
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 said:
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 said:
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?


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



:

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
 
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 said:
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 said:
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 said:
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



:

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?


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



:

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
 
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 said:
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 said:
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 said:
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>;
}

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



:

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?


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



:

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
 
Back
Top