Solved

PHP to C#

Posted on 2013-01-26
7
271 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
3 Use Cases for Connected Systems

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now