Solved

PHP to C#

Posted on 2013-01-26
7
279 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get sourcecode path 14 46
Header Font Size in Grid View 6 23
JSON decode 5 16
how to block posted data except coming from specific remote ADDR 11 12
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

762 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