请考虑以下代码:我的代码http://i44.tinypic.com/28hhdw4.jpg
正如您所看到的,我们在第28行.有没有办法在此时看到函数的返回值,而不让代码返回调用函数?
Foo.Bar()是一个函数调用,它生成一个唯一的路径(例如).所以这不是常数.
在immidiate窗口中输入?Foo.Bar()也不起作用,因为那会重新评估代码:
?Foo.Bar()
"80857466"
?Foo.Bar()
"2146375101"
?Foo.Bar()
"1106609407"
?Foo.Bar()
"792759112"
Run Code Online (Sandbox Code Playgroud)
在VB.NET中,可以在Watch中输入函数名称,然后将其作为变量进行威胁.
但在C#中,这是不可能的,还有其他任何提示吗?
PS:重写不是一种选择.
MyListBox我的屏幕上有一个ListBox()和一个Textbox(MyTextBox).
ListBox中填充了List(Of T),它们都是自定义项.
现在我尝试这样做:
ListBox的数据源是List(Of T).
现在,当项目更改时,我希望文本框更新为ListBox中所选项目的特定属性.
在代码中,这意味着:
Me.MyListBox.DisplayMember = "SelectionName"
Me.MyListBox.ValueMember = "Id"
MyTextbox.DataBindings.Add(New Binding("Text", Me._listOfItems, "SelectedItem.Comment", True, DataSourceUpdateMode.OnPropertyChanged))
Me.MyListBox.DataSource = Me._listOfItems
Run Code Online (Sandbox Code Playgroud)
这不起作用.但是当我绑定到SelectedValue而不是SelectedItem时,它完美地工作.
该_listOfItems声明为这样的:
Dim _listOfItems As List(Of MyItem) = New List(Of MyItem)()
Run Code Online (Sandbox Code Playgroud)
MyItem这是哪个:
public class MyItem
{
public string SelectionName { get; set; }
public int Id { get; set; }
public string Comment { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我尝试重写ToString()in MyItem以便它会使用它.但这也不起作用.
有人想试一试吗?
谢谢!
-Snakiej
不生成app.config.在我的团队中有一个人拥有Visual Studio 2008,他创建了一个Web服务.
然后就是我,将这个web服务添加到控制台项目中.
添加服务引用没有问题,但没有生成有效的app.config.它只是空的
<configuration>
</configuration>
Run Code Online (Sandbox Code Playgroud)
当我在我的服务引用中禁用"重用类型"时它可以工作,但后来我得到了一个模棱两可的错误.
这是一个错误吗?
我发现Visual Studio在"添加服务引用"这个时没有生成app.config内容,但是那里没有解决方案,所以我想我再次遇到问题了.
谢谢
在不安全的上下文中考虑以下代码:
string mySentence = "Pointers in C#";
fixed (char* start = mySentence) // this is the line we're talking about
{
char* p = start;
do
{
Console.Write(*p);
}
while (*(++p) != '\0');
}
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
这很好用.
根据http://msdn.microsoft.com/en-us/library/f58wzh21(v=VS.100).aspx我应该能够替换我标记的行
fixed(char* start = &mySentence[0])
Run Code Online (Sandbox Code Playgroud)
但不幸的是VS给了我以下错误.
无法获取给定表达式的地址
这个错误在我身边吗?
VS.NET 2010 Premium.
考虑一下:
Function Foo
{
param(
#????
)
}
Run Code Online (Sandbox Code Playgroud)
我想像这样打电话给Foo:
Foo -Bar "test"
Run Code Online (Sandbox Code Playgroud)
没有它爆炸,我没有指定$ bar param.那可能吗?:)
更新:
我希望这个工作:
Function IfFunctionExistsExecute
{
param ([parameter(Mandatory=$true)][string]$func, [parameter(Mandatory=$false)][string]$args)
begin
{
# ...
}
process
{
if(Get-Command $func -ea SilentlyContinue)
{
& $func $args # the amperersand invokes the function instead of just printing the variable
}
else
{
# ignore
}
}
end
{
# ...
}
}
Function Foo
{
param([string]$anotherParam)
process
{
$anotherParam
}
}
IfFunctionExistsExecute Foo -Test "bar"
Run Code Online (Sandbox Code Playgroud)
这给了我:
IfFunctionExistsExecute : A …Run Code Online (Sandbox Code Playgroud) 我想这样做:
List<Parent> test = new List<Child>();
Run Code Online (Sandbox Code Playgroud)
我班的完整代码是这样的:
class Program
{
public static void Main(string[] args)
{
List<Parent> test = new List<Child>();
test.Add(new Child());
test.Add(new AnotherChild());
}
}
class Parent { }
class Child : Parent { }
class AnotherChild : Parent { }
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我为什么这给了我这个错误:
错误2无法将类型'System.Collections.Generic.List'转换为'System.Collections.Generic.List'd:\ personal\documents\visual studio 2010\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs 20 24 ConsoleApplication3
为什么这有效?
Parent[] test = new Child[10];
List<Parent> result = test.ToList();
Run Code Online (Sandbox Code Playgroud)
谢谢 :)
- 对:
现在我知道原因了:List被编译为List`1和List to List`2.他们没有任何关系.
我使用Silverlight 4工具包创建了Silverlight图表,即4月发布.
请考虑以下图表:
<Grid x:Name="LayoutRoot" Background="White">
<Charting:Chart Title="Chart to test" Name="MySuperChart">
<Charting:LineSeries x:Name="MyLineSeries" Title="Something" />
</Charting:Chart>
</Grid>
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.我可以访问图表中的系列MySuperChart.Series[0]但是当我尝试引用MyLineSeries时,它似乎是空的.
图片http://i41.tinypic.com/9k4h7t.png
完整视图
考虑以下XML:
<?xml version="1.0" encoding="utf-8"?>
<treelist id="foo" displayname="display">
<treelink id="link" />
</treelist>
Run Code Online (Sandbox Code Playgroud)
我已经设置了以下代码:
private static void Main(string[] args)
{
StreamReader result = File.OpenText(@"test.xml");
var xmlTextReader = new XmlTextReader(result.BaseStream, XmlNodeType.Document, null);
XDocument load = XDocument.Load(xmlTextReader);
var xmlSerializer = new XmlSerializer(typeof (TreeList));
var foo = (TreeList) xmlSerializer.Deserialize(load.CreateReader());
}
Run Code Online (Sandbox Code Playgroud)
这些是我的实体:
[Serializable]
[XmlRoot("treelink")]
public class TreeLink
{
[XmlAttribute("id")]
public string Id { get; set; }
}
[Serializable]
[XmlRoot("treelist")]
public class TreeList
{
[XmlAttribute("id")]
public string Id { get; set; }
[XmlAttribute("displayname")]
public string DisplayName { …Run Code Online (Sandbox Code Playgroud) 我试图找出Where(Expression)和Single(Expression)之间的区别.
Expression传递给单个转发到Where函数吗?
例如,这两个陈述是一样的吗?
var result = context.Persons.Single(p => p.ID == 5);
var result2 = context.Persons.Where(p => p.ID == 5).Single();
Run Code Online (Sandbox Code Playgroud) 请考虑以下DynamoDb表:
TableName:foo-bar
HashKey:Foo, str
RangeKey:Bar, str
Name:Baz, str
现在有了vogels API,我试图插入一个带有HashKey,一个新的RangeKey和一个Name的项目.
但是对于给定的HashKey,名称不能存在:
所以我们定义了vogels API的表格布局:
var foobar = vogels.define("foo-bar", {
tableName: "foo-bar",
hashKey: "foo",
rangeKey: "bar",
schema: {
"foo": Joi.string(),
"bar": Joi.string(),
"name": Joi.string()
}
});
Run Code Online (Sandbox Code Playgroud)
然后插入项目:
var itemToInsert = { foo: "foo", bar: "bar2", name: "TEST" };
var params = {};
params.ConditionExpression = "foo <> :foo AND name <> :name";
params.ExpressionAttributeValues = {
":foo": itemToInsert.foo,
":name": itemToInsert.name
};
foobar
.create(itemToInsert, params, function(error, data) {
if(error) …Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×2
function ×2
arguments ×1
charts ×1
data-binding ×1
generics ×1
linq ×1
list ×1
pointers ×1
powershell ×1
return ×1
return-value ×1
silverlight ×1
system.xml ×1
vb.net ×1
web-services ×1
winforms ×1
wsdl ×1
xml ×1