如何从函数返回STRUCT [英] How return STRUCT from function
本文介绍了如何从函数返回STRUCT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct STUDENT
{
public CookieContainer fio;
public string htmlx;
}
public Form1()
{
InitializeComponent();
var s = impulse();
}
public ... impulse()
{
STRUCT str;
str.fio= "Surname";
str.htmlx = "asdas"
}
return str
}
推荐答案
public STUDENT impulse()
并将STRUCT
替换为STUDENT
.
and replace STRUCT
with STUDENT
.
与任何其他类型完全相同:
Exactly as with any other type:
struct Student { /* ... */ }
//...
Student Impulse() { //what's wrong with you naming?
Student student = new Student();
student.FullName = "Vasiliy Ivanovich Pupkin";
student.Html = "How knows what the hell is that?";
// I changed names to humanly style according to Microsoft naming conventions, removed ugly abbreviation "fio" // I know what do you mean, how abut others?
}
但是理性的人会做这样的事情:
But reasonable people do something like this:
struct Student {
internal Student(string fullName, string html) { FullName = fullName; Html = html; }
internal string FullName;
internal string Html;
}
//...
Student Impulse() {
return new Student("Vasiliy Ivanovich Pupkin", "How knows what the hell is that?");
}
// the simplicity of this method suggests that it makes no sense, but you need just an idea...
好吧,在CodeProjects上问了35个问题之后…(叹气)…
我想你需要完全不同的东西.这个:
Microsoft Q209354 .
没有冒犯,好吗?您真的需要那个.
祝你好运товарищ,
Well, after 35 questions asked on CodeProjects… (sigh)…
I guess you need completely different thing. This:
Microsoft Q209354.
No offense, OK? You really need exactly that.
Good luck, товарищ,
这篇关于如何从函数返回STRUCT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文