public string MessageItem (string ItemName)
{
get { return dsMessageContents.Tables["input"].Rows[0].ToString();}
}
Run Code Online (Sandbox Code Playgroud)
我收到2个错误:
我有一个GridView从DataSource连接两个表的值中检索值,我需要在代码隐藏中获取这些值并将它们作为一个传递给它String.关于什么是最好的方法的任何想法?以下是我GridView的aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDsPoNumber" EnableModelValidation="True" Visible="True"
DataKeyNames="PO_NUMBER,SITE_NAME">
<Columns>
<asp:BoundField DataField="PO_NUMBER" HeaderText="PO_NUMBER"
SortExpression="PO_NUMBER" />
<asp:BoundField DataField="SITE_NAME" HeaderText="SITE_NAME"
SortExpression="SITE_NAME" />
</Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud) 我正在定义一个lambda并通过追加"()"立即调用它.
尝试:
int i = (() => 0) ();
Run Code Online (Sandbox Code Playgroud)
错误:
错误CS0119:表达式表示
anonymous method', where a方法组'是预期的
这是为什么?
我正在运行一些非常简单的测试代码来查看linq查询中常量的影响,而我找不到重载...
这篇MSDN文章特别提到了skip/take的lambda重载,但我似乎找不到它.
"特别注意在进行分页时使用Skip和Take.在EF6中,这些方法有一个lambda重载,有效地使缓存的查询计划可重用,因为EF可以捕获传递给这些方法的变量并将它们转换为SQL参数."
他们遵循以下代码示例:
var customers = context.Customers.OrderBy(c => c.LastName);
for (var i = 0; i < count; ++i)
{
var currentCustomer = customers.Skip(() => i).FirstOrDefault();
ProcessCustomer(currentCustomer);
}
Run Code Online (Sandbox Code Playgroud)
我的测试代码:
for(int i = 0; i<100; i++)
{
var result = dc.Products
//.Select(p => p.Name)
.OrderBy(p => p.Name)
.Skip(() => i)
.ToList();
}
Run Code Online (Sandbox Code Playgroud)
错误:无法将lambda表达式转换为类型'int',因为它不是委托类型
我是否在阅读失败,或者是否存在包含重载扩展方法的地方?我在使用EF 6.1.1.
我试图使用MVVM模式在WPF的WebBrowser窗口中打开HTML文件.
注意:我已经解决了我遇到的问题.现在这段代码按照需要运行.
<Window x:Class="MyProject.ViewHTMLPageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyProject.Utility"
Title="HTML Report" Height="454" Width="787"
>
<Grid Name="grid1">
<WebBrowser local:WebBrowserUtility.BindableSource="{Binding ReportPage}" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
namespace MyProject
{
public class ViewHTMLPageViewModel: ViewModelBase
{
public ViewHTMLPageView()
{
//Testing html page on load
_reportPage = "<table border='5'><tr><td> This is sample <b> bold </b></td></tr></table>";
OnPropertyChanged("ReportPage");
}
private string _reportPage;
public string ReportPage
{
get
{
return _reportPage;
}
set
{
if (_reportPage != value)
{
_reportPage = value;
OnPropertyChanged("ReportPage");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
using System; …Run Code Online (Sandbox Code Playgroud) 我刚刚在Visual Studio中创建了一个新的空白XAML/C#Windows应用商店应用.我尝试使用以下代码在Documents文件夹中创建一个文件:
// DEBUG ONLY:
StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync("Hey lol.txt");
Run Code Online (Sandbox Code Playgroud)
但它抛出了这个异常(我预期):
WinRT信息:访问指定位置(DocumentsLibrary)需要在清单中声明一种功能.
哪个好.我期待它.所以我去Package.appxmanifest,去Capabilities标签,让我吃惊,没有列出"DocumentsLibrary"的能力.
如果它不存在,我该如何启用它?

c# windows-runtime windows-store-apps appxmanifest known-folders
我在flowlayoutpanel上有很多按钮,然后有文本标签来打破流程.标签和标签本身之前的最后一个按钮SetFlowBreak.一切都很好,但我不明白,为什么文本标签下面有这么多空间?如果窗体的大小调整得如此之窄,以至于只有一列按钮,那么不需要的空间就会消失.有人可以解释如何删除该空间?
码:
public Form1()
{
InitializeComponent();
for (int i = 1; i <= 100; i++)
{
Button button = new Button();
button.Text = i.ToString();
button.Width = 150;
button.Height = 50;
button.Margin = new Padding(5);
flowLayoutPanel1.Controls.Add(button);
if (i % 10 == 0)
{
flowLayoutPanel1.SetFlowBreak(button, true);
Label label = new Label();
label.Text = "Some random text";
label.AutoSize = true;
label.Margin = new Padding(5, 5, 0, 0);
label.BackColor = ColorTranslator.FromHtml("#ccc");
flowLayoutPanel1.Controls.Add(label);
flowLayoutPanel1.SetFlowBreak(label, true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
和几个图像来表明我的意思:
我需要使用以下公式以预定义的精度计算PI:

所以我最终得到了这个解决方案.
private static double CalculatePIWithPrecision(int presicion)
{
if (presicion == 0)
{
return PI_ZERO_PRECISION;
}
double sum = 0;
double numberOfSumElements = Math.Pow(10, presicion + 2);
for (double i = 1; i < numberOfSumElements; i++)
{
sum += 1 / (i * i);
}
double pi = Math.Sqrt(sum * 6);
return pi;
}
Run Code Online (Sandbox Code Playgroud)
所以这是正确的,但我遇到了效率问题.精度值为8或更高时,它非常慢.
是否有更好(更快!)的方法来使用该公式计算PI?
我想在WCF客户端的App.config中设置maxReceivedMessageSize.
如果maxReceivedMessageSize等于或小于4215则可以正常工作.虽然将其设置为4216或高于它的任何值时,将采用默认值65536.


我的客户代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IConexaApiServic" maxReceivedMessageSize="4216" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://svsr02.conexa.local/HelloService/ConexaApiService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConexaApiServic"
contract="ConexaApiService.IConexaApiService" name="BasicHttpBinding_IConexaApiService" />
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
和相关的服务器代码
<basicHttpBinding>
<binding name="BasicHttpEndpoint_MPSAPIServic" maxReceivedMessageSize="2000000">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpEndpoint_HelloService" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2000000">
</binding>
</basicHttpBinding>
<service name="IIS_test123.HelloService">
<endpoint address="ConexaApi" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint_HelloService" contract="IIS_test123.IHelloService"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/API/ConexaApiService" />
</baseAddresses>
</host>
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?
我正在将列表中的项目添加到 CheckedListBox。我希望该框向用户显示项目的友好名称,但在用户选择它时有一个“秘密”实际值可供使用。
foreach (string s in x)
{
checkedlistBox1.Items.Add(friendlyValue);
//Now how do I get this to have the real value?
}
Run Code Online (Sandbox Code Playgroud)
使用下拉菜单,我可以将 DisplayName 和 ValueName 设置为某些内容并使用以下内容:
combobox1.Items.Add(new ComboBoxItem { friendlyValue = x, realValue = y });
Run Code Online (Sandbox Code Playgroud)
我似乎无法用 CheckedListBox 做到这一点。