我现在正在努力理解当它表示使用'out'关键字我们能够返回多个值时它意味着什么.例如,来自msdn网站(https://msdn.microsoft.com/en-us/library/ee332485.aspx):"......以下示例使用out来通过单个方法调用返回三个变量."
class OutReturnExample
{
static void Method(out int i, out string s1, out string s2)
{
i = 44;
s1 = "I've been returned";
s2 = null;
}
static void Main()
{
int value;
string str1, str2;
Method(out value, out str1, out str2);
// value is now 44
// str1 is now "I've been returned"
// str2 is (still) null;
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定我是不是只是没有正确阅读说明,但似乎Method()实际上并没有返回(不使用'return'关键字)任何东西并基本上分配字段(类似地通过传递通过ref).这与其他来源一致,他们声明使用'out'可以返回 多个值.我是否误解了返回词的背景,或者是否是我不能正确理解这个概念的东西?
我正在尝试使用“阻止此步骤直到步骤完成”进行转换,但它似乎不起作用:
从图片上显示的方式来看,假设“total EPOs.DAT、VSE、ESP”应该在“Filtrar GESTIONADO ny”和“Select value Kibana 2”尚未完成之前运行,对吗?如果没有,我怎样才能达到这样的目的?
谢谢。
我想这是一个非常简单的问题,可能是一个已经多次回答的问题.但是,我真的对C++感到厌烦,并且搜索无法找到解决方案.我真的很感激帮助.
基本上:
#ifndef ANIMAL_H
#define ANIMAL_H
class Animal
{
public:
void execute();
void setName(char*);
Animal();
virtual ~Animal();
private:
void eat();
virtual void sleep() = 0;
protected:
char* name;
};
class Lion: public Animal
{
public:
Lion();
private:
virtual void sleep();
};
class Pig: public Animal
{
public:
Pig();
private:
virtual void sleep();
};
class Cow: public Animal
{
public:
Cow();
private:
virtual void sleep();
};
#endif
Run Code Online (Sandbox Code Playgroud)
是头文件,其中:
#include <iostream>
#include "Animal.h"
using namespace std;
Animal::Animal()
{
name = new char[20]; …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译以下代码:
public static void RequireOrPermanentRedirect<T>(this System.Web.UI.Page page, string QueryStringKey, string RedirectUrl, out T parsedValue)
{
string QueryStringValue = page.Request.QueryString[QueryStringKey];
if (String.IsNullOrEmpty(QueryStringValue))
{
page.Response.RedirectPermanent(page.ResolveUrl(RedirectUrl));
}
try
{
parsedValue = (T)Convert.ChangeType(QueryStringValue, typeof(T));
}
catch
{
page.Response.RedirectPermanent(RedirectUrl);
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到编译器错误:
Error 1 The out parameter 'parsedValue' must be assigned to before control leaves the current method
Run Code Online (Sandbox Code Playgroud)
它是一种我已经使用了一段时间的扩展方法,但我想稍微扩展一下,以便我不必重新分析值以在页面内使用它.
目前的用法:
Page.RequireOrPermanentRedirect<Int32>("TeamId", "Default.aspx");
int teamId = Int32.Parse(Request.QueryString["TeamId"]);
Run Code Online (Sandbox Code Playgroud)
我想做的是:
private Int32 teamId;
protected void Page_Load(object sender, EventArgs e)
{
Page.RequireOrPermanentRedirect<Int32>("TeamId", "Default.aspx", out teamId);
}
Run Code Online (Sandbox Code Playgroud)
我刚刚创建并抛弃的当前(工作)代码T value …
问题是:我想要一个泛型函数,它具有泛型类型的out参数.将泛型类型限制为ref-type,并且没有问题.但我想要一个完全不受限制的通用类型!没有new()或类/ struct限制!
public class A
{ }
public class B<T> : A
{
public T t;
public B(T i)
{
this.t = t;
}
}
public static class S
{
public static bool Test<T>(ref A a, out T t)
{
C<T> c = a as C<T>;
if(c != null)
{
t = c.t;
return true;
}
else
return false;
}
}
class Run
{
static void Main(string[] args)
{
C<SomeType> c = new C<SomeType>(new SomeType(...));
SomeType thing;
S.Test<SomeType>(c,thing);
}
} …Run Code Online (Sandbox Code Playgroud) 我想B从另一个类初始化一个类型的对象A,为什么我仍然得到null?是否可以在不使用ref和out修饰符的情况下完成?
class A
{
public void Initialize(B value)
{
if (value == null)
{
value = new B();
}
}
}
class B
{
}
class Program
{
static void Main(string[] args)
{
A a = new A();
B b = null;
a.Initialize(b);
}
}
Run Code Online (Sandbox Code Playgroud)
[upd.]我认为b变量可以传递,ref因为它是类的实例.
可能重复:
为什么没有办法在java中通过引用传递
任何人都可以告诉我为什么Java在处理方法参数以通过引用传递时不提供C#"out"类型功能?我的意思是为什么它不允许我们传递原始数据类型,例如boolean,通过引用传递.我也尝试过包装类java.lang.Boolean但仍无济于事.它仍然不允许我通过引用传递变量.
是否有任何特定的原因,即使在版本7中Java仍未提供此功能?
public static string ChangeDeviceState(int deviceID, DeviceState nextState)
{
bool temp1;
string temp = "";
return ChangeDeviceState(deviceID, nextState, temp1, temp, "", "", "", "", "");
}
public static string ChangeDeviceState(int deviceID, DeviceState nextState, out bool? isAccessToken, out String challengeOrToken, string accessToken, string serialNumber, string MACAddress, string deviceModel, string answer )
{
Run Code Online (Sandbox Code Playgroud)
我所要做的就是有另一种方法,其他参数不是必需的.我bool isAccessToken必须是可空的,challengeOrToken必须是一个out param.
我收到了非法的参数错误.
我真的不明白c#中的这些参数功能.任何帮助是极大的赞赏.
我有一个方法将字符串传递给类.出于测试原因,我现在使用了一个按钮.我在论坛中搜索了类似的问题,但他们提到了php和其他我无法理解的情况.该类从字符串中删除几个字符,并根据标题将值分配给3个不同的字符串.我需要将这3个字符串返回给调用者,并将其编码为以下内容.
呼叫者:
private void button4_Click(object sender, EventArgs e)
{
string a, b, c;
string invia = textBox8.Text.ToString();
Stripper strp = new Stripper();
strp.Distri(invia, out a, out b, out c);
textBox7.Text = a;
textBox7.Text = b;
textBox7.Text = c;}
Run Code Online (Sandbox Code Playgroud)
类:
class Stripper
{
public void Distri (string inArrivo, out string param1, out string param2, out string param3)
{
string corrente="";
string temperatura="";
string numGiri="";
string f = inArrivo;
f = f.Replace("<", "");
f = f.Replace(">", "");
if (f[0] == 'I')
{ …Run Code Online (Sandbox Code Playgroud) for i in range(len(lst)):
if lst[i][0]==1 or lst[i][1]==1:
lst.remove(lst[i])
return lst
Run Code Online (Sandbox Code Playgroud)
这给出了"IndexError:list index超出范围"为什么会发生这种情况?