c# - 关于返回的问题?

标签 c# .net

在此代码中(来自 WCF REST starterkit - preview2):

protected override SampleItem OnAddItem(SampleItem initialValue, out string id)
        {
            // TODO: Change the sample implementation here
            id = Guid.NewGuid().ToString();
            this.items.Add(id, initialValue);
            return initialValue;
        }

我是返回字符串形式的 id,还是返回 SampleItem 形式的 initialValue?

编辑: 看起来我都回来了,那么将方法调用的简单示例分配给几个变量会是什么样子呢?

最佳答案

您将在作为参数传递给该方法的字符串中取回 id。此外,该方法将返回 SampleItem 实例。

SampleItem myItem = new SampleItem();
string newId = string.Empty;
myItem = OnAddItem(myItem, out newId);
// now myItem will be assigned with SampleItem returned from the
// OnAddItem method, and newId will be updated with the id assigned
// within that method

关于c# - 关于返回的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/883168/

相关文章:

.net - 如何让 nhibernate 在 .net 4 中流畅工作

.net - OracleBulkCopy 不支持触​​发器

.net - 如何将可为空的 bool 值绑定(bind)到复选框?

c# - 为什么 Code Contracts 声称此代码为 "Ensures is false"?

c# - C# 程序能否将文本文件读入内存,然后将该对象传递给需要文件名的方法?

c# - 将对象传递给用户控件和 + 未将对象引用设置为对象的实例

c# - 如何使用 LINQ 从没有主键的表中插入/更新/删除记录

c# - 无法让 ListView 停止闪烁

c# - 如何告诉 ReSharper 自动格式化每行一个参数

c# - XAML 命名空间 http ://schemas. microsoft.com/winfx/2006/xaml 未解析