Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I find a algorithm writen by javascript,now i want to convert it to C#,
Any tool can do this?
Well, you could start with Javascript.Net to try your code within another application before rewriting/converting it. Whatever you do, don't rely on auto-generated code for an algorithm of any importance.
If memory serves, there was actually a flavor of JavaScript that ran on the .Net CLR. I don't think it ever caught on.
Using javascript.net or jscript with .net Reflector, will save you brain and keyboard, may be
There is a dialect of JavaScript called UnityScript that can be converted into C# using the UnityScript-to-C# converter.
I also wrote a tool called universal-transpiler can convert a small subset of JavaScript into C# and several other languages.
Input in JavaScript:
function add(a,b){
var g = [3,4,5];
return a+b+(g[0])+(g.length);
}
function divide(a,b){
return a/b;
}
Output in C# from universal-transpiler:
public static int add(int a,int b){
int[] g={3,4,5};
return a+b+(g[0])+(g.Length);
}
public static int divide(int a,int b){
return a/b;
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
String Interpolation
in this example, there is a variable declaration that I haven't seen before and don't know what it is:
var jh = (firstName: "Jupiter", lastName: "Hammon", born: 1711, published: 1761);
there is Anonymous Types in C# but it uses curly braces.
the jh.GetType() returns
System.ValueTuple 4[System.String,System.String,System.Int32,System.Int32]
but ValueTuple generics are not key-value pairs. they have some items. this syntax is more like a dictionary of named fields.
so my question is what is this syntax called? I'm looking for Microsoft docs page for getting documentation and details about this syntax.
As you already mentioned, this is ValueTuple. You can see here for some description and comparison with a "ordinal" Tuples. The official documentation also available here.
The code you showed is the just a typical declaration of such a ValueTuple. The syntax was introduced in C# 7.0.
To replace var, you can use the following:
(string firstName, string lastName, int born, int published) jh = (firstName: "Jupiter", lastName: "Hammon", born: 1711, published: 1761);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Currently, I have something like the following:
public char functName(int n)
{
some functionality....
if(condition1)
return convertFuncToChar(variable) + functName(modifiedNumber);
else
return convertFuncToChar(variable);
}
however, I realize that doesn't give me a string (and the syntax shows that there's an error).
I know that for c++, I would most likely use char* to initialize the function, but this is C#.
I don't think it works if I initialize with String either.
Assuming I understand the question correctly, you can take advantage of two things:
1) all basic types implement .ToString(), which creates a string for you
2) string implements operator+()
The following is an example of a recursive function that will recursively concatenate characters to create a string. The output is the number in reverse as a string.
static string funcName(int n)
{
if (n<10)
return (n%10).ToString();
return (n%10).ToString() + funcName(n/10);
}
Of course, it would be more efficient to write this non-recursively.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I need a library to read 2D barcode (datamatrix) from images on C# project (windows Forms).
I tried using some SDKs, but the SDKs I tried are not free.
Is there any free SDK for reading 2d Barcode from images?
There's an example available:
using DataMatrix.net; // Add ref to DataMatrix.net.dll
using System.Drawing; // Add ref to System.Drawing.
[...]
// ---------------------------------------------------------------
// Date 180310
// Purpose Get text from a DataMatrix image.
// Entry sFileName - Name of the barcode file (PNG, + path).
// Return The text.
// Comments See source, project DataMatrixTest, Program.cs.
// ---------------------------------------------------------------
private string DecodeText(string sFileName)
{
DmtxImageDecoder decoder = new DmtxImageDecoder();
System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(sFileName);
List<string> oList = decoder.DecodeImage(oBitmap);
StringBuilder sb = new StringBuilder();
sb.Length = 0;
foreach (string s in oList)
{
sb.Append(s);
}
return sb.ToString();
}
You'll need DataMatrix.net!
Best free Datamatrix coder\decoder that i've used is libdmtx: http://www.libdmtx.org/ . It has c# wrapper, so feel free to use it. I can't write sample code right now, but if you won't be able to handle it yourself, i'll help you a bit later with that.
EDIT:
libdmtx comes with console utils - if you will be able to read your barcodes with console app, you surely will read it using code.
EDIT2:
Here's code samples: http://libdmtx.wikidot.com/libdmtx-net-wrapper
I wonder if you have pictures containing some other info, except the barcode. The thing is - i don't know any free\open source lib to handle finding barcode on a picture, containing any other data properly.
And here's the link to other datamatrix implementations: http://www.libdmtx.org/resources.php
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I ran a static code analysis tool on our tool and looking at its results the code below was one of the things it was talking about:
SpreadSnapshot oSnap = new SpreadSnapshot();
using (oSnap.SetRowCol(fpSpread, row, col))
{
SpreadSetComboBox(fpSpread, list, displayProperty);
}
So I changed it to the code below and it fixed the error that the tool was talking about:
using (SpreadSnapshot oSnap = new SpreadSnapshot())
{
oSnap.SetRowCol(fpSpread, row, col);
SpreadSetComboBox(fpSpread, list, displayProperty);
}
So in your opinion Which style of coding do you think is more appropriate and less error-prone?
Thanks
The latter - it ensures that you don't end up using oSnap after the using statement.
Aside from anything else, it would be pretty odd for SetRowCol to return something disposable... what would that even mean?
The two mean completely different things, unless SetRowCol returns this at the end. In the first, you're disposing the results of SetRowCol. In the second, you're disposing the SpreadSnapshot.
If both are disposable, you should do a using for both:
using (SpreadSnapshot oSnap = new SpreadSnapshot())
using (oSnap.SetRowCol(fpSpread, row, col))
{
SpreadSetComboBox(fpSpread, list, displayProperty);
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
I will need to write an app to run statistical analysis on a DataGrid. Pp and Ppk is easy to do with standard deviation calculation in C#. But Some number such as estimated deviation (rBar/d2) used for Cp and Cpk - that is too complex (for me ) to code. Are there existing libraries, commercial or open source, that I can implement?
Extreme Optimization might be something you are looking for.
Edit
How about SPC Chart?
You might wanna check out Sho, it's a tool for doing stuff with data and it provides a lot of math libraries.
http://channel9.msdn.com/Blogs/Charles/John-Platt-Introduction-to-Sho
http://research.microsoft.com/en-us/projects/sho/
I have used MathNet.Numerics for these type calculations.
https://www.nuget.org/packages/MathNet.Numerics/
https://numerics.mathdotnet.com/
Example for cp and cpk:
public class ProcessPerformance
{
public static ProcessPerformanceResult Calculate(double[] data,double lsl,double usl,double sigma =3.0,double cpSigma=6.0)
{
if(data.Count() ppkLsl ? ppkLsl : ppkUsl;
var cP = (usl - lsl) / (descriptiveStatistics.StandardDeviation * cpSigma);
var median = MathNet.Numerics.Statistics.Statistics.Median(data);
return new ProcessPerformanceResult(){Cp=cP,Cpk=cPk,Median= median, DescriptiveStatistics=descriptiveStatistics};
}
public class ProcessPerformanceResult
{
//https://en.wikipedia.org/wiki/Process_capability_index
public double Cpk { get; set; }
public double Cp {get;set;}
public double Median {get;set;}
public MathNet.Numerics.Statistics.DescriptiveStatistics DescriptiveStatistics {get;set;}
}
}