out

Why would ref be used for array parameters in C#?

不羁的心 提交于 2019-11-30 05:18:42
问题 I read the page Passing Arrays Using ref and out (C# Programming Guide) and was wondering why we would need to define an array parameter as a ref parameter when it is already a reference type. Won't changes in the callee function be reflected in the caller function? 回答1: Won't changes in the callee function be reflected in the caller function? Changes to the contents of the array would be reflected in the caller method - but changes to the parameter itself wouldn't be. So for example: public

java.net.socketException:operation time out when running app on real device

怎甘沉沦 提交于 2019-11-29 17:41:55
this code works fine on emulator, but on real device it gives java.net.SocketException :the operation timed out ive got a php script running on my xampp server. package com.example.new1; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import android.os.AsyncTask; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.TextView; public class MainActivity extends Activity { TextView tx; StringBuilder stringBuilder; @Override protected void onCreate

Console.ReadLine add 48 to int

梦想与她 提交于 2019-11-29 16:11:56
I get 48 when I input 0 to a ReadLine(). Is this a bug? class Program { static void Main(string[] args) { string name; int age; readPerson(out name, out age); } static void readPerson(out string name, out int age) { Console.Write("Enter name: "); name = Console.ReadLine(); Console.Write("Enter age: "); age = Console.Read(); Console.WriteLine("Name: {0}; Age: {1}", name, age.ToString()); } } According to the MSDN documentation, the Console.Read method returns: The next character from the input stream, or negative one (-1) if there are currently no more characters to be read. So, really what you

paypal express checkout =>Error: Security header is not valid

我只是一个虾纸丫 提交于 2019-11-29 00:20:16
问题 Error : Security header is not valid Array ( [TIMESTAMP] => 2014%2d04%2d29T07%3a24%3a29Z [CORRELATIONID] => 6af6749c848d6 [ACK] => Failure [VERSION] => 109%2e0 [BUILD] => 10800277 [L_ERRORCODE0] => 10002 [L_SHORTMESSAGE0] => Security%20error [L_LONGMESSAGE0] => Security%20header%20is%20not%20valid [L_SEVERITYCODE0] => Error ) I am getting this error again and again and cannot move ahead. I had checked all the api username, password and signature, all are correct, but the main problem is that,

C# out parameter performance

落爺英雄遲暮 提交于 2019-11-28 21:16:55
Do out parameters in C# have any performance implications I should know about? (Like exceptions) I mean, is it a good idea to have a method with an out parameter in a loop that will run a couple of million times a second? I know it's ugly but I am using it the same way as Int32.TryParse is using them - returning a bool to tell if some validation was successful and having an out parameter containing some additional data if it was successful. I doubt that you'll find any significant performance penalty to using an out parameter. You've got to get information back to the caller somehow or other -

C# PInvoke out strings declaration

跟風遠走 提交于 2019-11-28 13:30:42
In C# PInvoke, how do I pass a string buffer so that the C DLL fills it and returns? What will be the PInvoke declaration? The C function declaration is int GetData(char* data, int buflength); In C#, I have declared it as [DllImport(DllName)] static extern Int32 GetData([MarshalAs(UnmanagedType.LPStr)]StringBuilder receiveddata, Int32 buflen); Is it correct? I'm passing the StringBuilder variable like this int bufferLength = 32; StringBuilder data = new StringBuilder(bufferLength); int result = GetData(data, bufferLength); I would like to know is it correct or not? Thanks I believe it's

How to declare a generic delegate with an out parameter [duplicate]

懵懂的女人 提交于 2019-11-28 09:39:56
This question already has an answer here: Func<T> with out parameter 4 answers Func<a, out b, bool> , just don't compile, how to declare that i want the second parameter be an out one? I want to use it like this: public class Foo() { public Func<a, out b, bool> DetectMethod; } Andrew Bezzub Actually, Func is just a simple delegate declared in the .NET Framework. Actually, there are several Func delegates declared there: delegate TResult Func<TResult>() delegate TResult Func<T, TResult>(T obj) delegate TResult Func<T1, T2, TResult>(T1 obj1, T2 obj2) delegate TResult Func<T1, T2, T3, TResult>(T1

How to explicitly discard an out argument?

主宰稳场 提交于 2019-11-28 09:34:39
I'm making a call: myResult = MakeMyCall(inputParams, out messages); but I don't actually care about the messages. If it was an input parameter I didn't care about I'd just pass in a null. If it was the return I didn't care about I'd just leave it off. Is there a way to do something similar with an out, or do I need to declare a variable that I will then ignore? Starting with C# 7.0, it is possible to avoid predeclaring out parameters as well as ignoring them. public void PrintCoordinates(Point p) { p.GetCoordinates(out int x, out int y); WriteLine($"({x}, {y})"); } public void

Why can't an out parameter have a default value?

懵懂的女人 提交于 2019-11-28 03:11:28
问题 Currently when trying to do something in a method that takes an out parameter, I need to assign the value of the out parameter in the method body, e.g. public static void TryDoSomething(int value, out bool itWorkerd) { itWorkerd = true; if (someFavourableCondition) { // if I didn't assign itWorked variable before this point, // I get an error: "Parameter itWorked must be assigned upon exit. return; } // try to do thing itWorkerd = // success of attempt to do thing } I'd like to be able to set

What is the purpose of the “out” keyword at the caller (in C#)?

余生长醉 提交于 2019-11-28 01:40:48
When a C# function has an output parameter, you make that clear as follows: private void f(out OutputParameterClass outputParameter); This states that the parameter does not have to be initialized when the function is called. However, when calling this function, you have to repeat the out keyword : f(out outputParameter); I am wondering what this is good for. Why is it necessary to repeat part of the function specification? Does anyone know? It means you know what you're doing - that you're acknowledging it's an out parameter. Do you really want the utterly different behaviour to happen