Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
//
string productName;
byte& local1 = (byte&) productName;
//
What is this byte&?
I really don't understand. I got code from my friend but I don't understand what this line wants to tell? Because it gives error or redline in my VS2012. Can anyone explain?
It's making local1 a reference byte type, but that's probably coming from some IL decompilation and not valid C# syntax. That result code will more likely happen if you decompile a IL function with a ref string parameter.
You can't compile that code using a C# compiler. There are many things that are legal in IL but there's no C# equivalent syntax, and that's usually the way it's decompiled back (which doesn't make it compilable) in a best-effort to make it look like C#
It is invalid. The closest syntax is byte? - which adds null support to byte.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I 've a doubt that researching I couldn't solve.
I want to pass a parameter using a var type to this method:
public static List<T[]> sortRequests<T>(List<T> _requests)
{
return null;
}
And I am calliinf the method here:
//Note: Thats code corresponds from an HttpRest service.
var _requests = await _requestService.Search(new SearchRequestSpecificationMapper().Map(searchRequestsViewModel));
var requests = sortRequests(_requests);
So VS 2015 is reporting about an error when I call the sortRequest() method.
Can anybody help me please?
Thank you very much in advance.
_requests is (presumably) not a List<T>.
You might be able to make it into a List<T> by caling ToList:
var requests = sortRequests(_requests.ToList());
However, I can't be certain without knowing more about your code, especially what the Search and Map functions do.
NOTE
Please be aware that there is no such thing as a var type in C#. var is just a bit of syntactic sugar that means "This variable has the type of whatever I assign to it when I declare it" - it's no different to just declaring it as the correct type.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
A few days ago I checked out the C# implementation of Binary Trees test # Computer Language Benchmark Game, and was weirdly surprised: the tree node there is described as a struct (TreeNode) referencing a class (Next) which has two fields of a TreeNode (strut) type. This obviously looks weird, so I updated this code to use a single class (i.e. ~ class TreeNode { TreeNode Left, Right }). My ItemCheck implementation was:
public int ItemCheck()
{
if (ReferenceEquals(Left, null)) // Such a node is always a leaf in this test
return 1;
return 1 + Left.ItemCheck() + Right.ItemCheck();
}
As you may find, it's quite similar to the original implementation. Nevertheless, the performance of this code was ~ 2.2x worse!
Can someone explain why this kind of "optimization" makes sense on .NET? I mostly want to understand what are some other implications of this - of course, if it's not simply a lack in C# / JIT compiler.
A bit more readable version of the same code with a few minor performance improvements can be found here: https://github.com/alexyakunin/BenchmarkGame-CSharp/blob/master/src/BinaryTrees/Program.cs
Update: I created an extra project for benchmarking this:
Code: https://github.com/alexyakunin/BenchmarkGame-CSharp/blob/master/src/Benchmarks/Program.cs
Benchmarking results: https://github.com/alexyakunin/BenchmarkGame-CSharp/blob/master/src/Benchmarks/BenchmarkDotNet.Artifacts/results/TreeNodeBenchmark-report-github.md
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a database field called "PIECE" which datatype is NUMERIC(11,0),
I must convert this field to a long-datatype.
This without any luck or succes, I'll keep getting the same error:
Wrong conversion...
I tried the next things:
(long)PIECE
long.Parse(PIECE.ToString().Trim())
But I'm still having the wrong conversion message,
is here someone who can help me?
This will do it:
var result = Convert.ToInt64(PIECE);
https://msdn.microsoft.com/en-us/library/0zahhahw(v=vs.110).aspx
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Found this csv parser: https://github.com/bytefish/TinyCsvParser
Following his example but I even added one int property.
By setting a negative value to that int, it gave me one unvalid row.
Couldn't find any solution for this simple? problem.
The type converter was using the wrong NumberStyle as default. I have fixed the problem and added a Test case to the project: https://github.com/bytefish/TinyCsvParser/issues/2.
You could also instantiate a custom converter with the right NumberStyle (see WithCustomConverter, Example), but I suggest simply updating to the latest version (0.6), which is also updated in NuGet.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Basically I have two questions:
1) How to emit or generate a IronPython code (tools, libs) in a C# application. The result of this process should be string consisting of real IronPython code not IL code.
2) How beneficial is the approach above over generating a IronPython code on your own (simply by using StringBuilder)?
I am looking for some code generator library similar to this IMAGINARY pseudo code generator:
IronPythonCodeGenerator generator = new IronPythonCodeGenerator();
Parameter param = new Parameter("str");
ParameterValue value=new ParameterValue(param,"This piece is printed by the generated code!!!");
Function function = IronPythonCodeGenerator.CreateFunction("PrintExtended",param);
function.AppendStatement("print",param);
function.AppendStatement(Statements.Return);
FunctionCall functionCall = new FunctionCall(function,value);
generator.MainBody.Append(function);
generator.MainBody.Append(functionCall);
Console.WriteLine(generator.MainBody.ToString());
, which outputs the IronPython code:
def PrintExtended( str ):
print str;
return;
PrintExtended("This piece is printed by the generated code!!!");
Reflection.Emit is for generating IL code, not for generating high-level language code. So if your target language is IronPython, building it up in a StringBuilder is probably your best bet.
It of course depends on your needs. If all you want to do is just generate code without wanting to change the order of methods, or modify methods after they've been defined etc., just constructing code in a StringBuilder and then compiling it would be the easiest way.