Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP to C#

Posted on 2013-01-26
7
278 Views
Last Modified: 2013-02-04
Hi,

How can I convert the attahed PHP code to C#?

ayha
stlvolume.php
0
Comment
Question by:ayha1999
  • 3
  • 3
7 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 38822306
First of all, remove all the $ !!!

The code snippet basically reads a binary file, so you will need to use BinaryReader. So, instead of the following

$fp = fopen($filepath, "rb");
$section = file_get_contents($filepath, NULL, NULL, 0, 79);
fseek($fp, 80);
$data = fread($fp, 4);
$numOfFacets = unpack("I", $data);
for ($i = 0; $i < $numOfFacets[1]; $i++){
	//Start Normal Vector
	$data = fread($fp, 4);
	$hold = unpack("f", $data);

Open in new window

you do:

using (BinaryReader fp = new BinaryReader(File.Open(filepath, FileMode.Open)))
{
    fp.BaseStream.Position = 80;
    var numOfFacets = fp.ReadInt32();
    for (int i = 0; i< numOfFacets; i++) {
         var hold = fp.ReadSingle();
// etcetera

Open in new window

0
 
LVL 7

Author Comment

by:ayha1999
ID: 38822329
could u please convert the complete code?

Thanks
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38822338
Hello ayha1999,
This is not a do-my-job-for-me site, but a collaboration site where volunteers try to solve your questions.
I already answered your question: "How can I convert the attahed PHP code to C#?"

From now on, you should try to do it by yourself and come back with any other question in order to acomplish your task.
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 7

Author Comment

by:ayha1999
ID: 38823422
Is there by php to c# conversion utility or php to asp.net project migration tool?

Thanks
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38823432
There is not such thing, as far as I know.
The problem is that you don't want to convert the language itself but the framework library. Even worst, the standard PHP library is not object oriented but just a collection of functions, while the .net framework library is fully OO.
So, there is not other solution than translating it manually, which is quiet easy for something that knows about it.
0
 

Assisted Solution

by:kottamgari
kottamgari earned 250 total points
ID: 38825738
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 38851681
Thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question