我有与此类似的代码:
public xyz (int? a)
{
if (a.HasValue)
{
// here DoSomething has parameters like DoSomething(int x)
blah = DoSomething(a);
Run Code Online (Sandbox Code Playgroud)
我收到错误(无法从int?转换为int).有没有办法我可以将变量'a'传递给我的函数而不必这样做DoSomething(int? x)?
With datagridview.Columns("PricePerUnit")
.ValueType = Type.GetType("System.Decimal")
.DefaultCellStyle.Format = "C"
End With
Run Code Online (Sandbox Code Playgroud)
数据表绑定到datagridview并在上面的代码中a如果我只是将值为5的行添加到"PricePerUnit"列,它将在datagridview列中显示为$ 5.00
同样地,我想显示类似于如果我只是将值为5的行添加到"DiscountPercentage"列中
应显示为5.00%
我需要一个字符串值来分配给DefaultCellStyle.Format来实现这一点.
如果我DefaultCellStyle.Format="P"自动使用它会将其乘以100,因此对于输入为5,它显示为500.00%而不是5.00%
有任何想法吗?
解决
dtb帮助我这样做(感谢他)
number.ToString("0.00\%") 获取十进制数和2个十进制整数
我正在尝试规范化任意链.Skip()并.Take()调用单个.Skip()调用,然后是可选的单个.Take()调用.
以下是预期结果的一些示例,但我不确定这些是否正确:
.Skip(5) => .Skip(5)
.Take(7) => .Skip(0).Take(7)
.Skip(5).Skip(7) => .Skip(12)
.Skip(5).Take(7) => .Skip(5).Take(7)
.Take(7).Skip(5) => .Skip(5).Take(2)
.Take(5).Take(7) => .Skip(0).Take(5)
.Skip(5).Skip(7).Skip(11) => .Skip(23)
.Skip(5).Skip(7).Take(11) => .Skip(12).Take(11)
.Skip(5).Take(7).Skip(3) => .Skip(8).Take(4)
.Skip(5).Take(7).Take(3) => .Skip(5).Take(4)
.Take(11).Skip(5).Skip(3) => .Skip(8).Take(3)
.Take(11).Skip(5).Take(7) => .Skip(5).Take(6)
.Take(11).Take(5).Skip(3) => .Skip(3).Take(2)
.Take(11).Take(5).Take(3) => .Skip(0).Take(3)
Run Code Online (Sandbox Code Playgroud)
任何人都可以确认这些是预期的正确结果吗?
这是我从示例中得出的基本算法:
class Foo
{
private int skip;
private int? take;
public Foo Skip(int value)
{
if (value < 0)
value = 0;
this.skip += value;
if (this.take.HasValue) …Run Code Online (Sandbox Code Playgroud) 我正在使用Fit/Fitnesse.我有一个看起来像这样的列夹具.
!|Get Stepstools Medication Id From Vocab and String| |Concept As String|Vocabulary Name Abbr|Vocabulary Concept Id|Stepstools Med Id?| |AMOXICILLIN|RXNORM|723|1| |AMOXICILLIN| | |1| |AUGMENTIN|RXNORM|151392|8| |AUGMENTIN| | |8| |Amoxicillin 1000 MG / Clavulanate 62.5 MG Extended Release Tablet| | |8|
我试图通过使用| |测试来传递空字符串值,当我运行它时,从前一行获取值并使用它.
我的夹具代码如下所示:
public class GetStepstoolsMedicationIdFromVocabAndString: ColumnFixture
{
public string VocabularyNameAbbr;
public string VocabularyConceptId;
public string ConceptAsString;
public string StepStoolsMedId()
{
MedicationMapping mapping = MedicationMapper.GetStepMedIdFromVocabNameIdAndStringMed(
VocabularyNameAbbr,
VocabularyConceptId,
ConceptAsString
);
if (mapping.SuccessfullyMapped)
{
return mapping.StepstoolsMedicationId.ToString();
}
else
{
return mapping.ErrorMessage;
} …Run Code Online (Sandbox Code Playgroud) 我总是遇到一个问题,我在Visual Studio(2008)中的项目变成了巨大的怪物,一切都被抛入Web应用程序项目.我知道从检查一些开源的东西,他们往往在解决方案中有多个项目,每个项目都有自己的职责.
有没有人对如何重构这个有任何建议?单独的项目与网络项目的一部分应该是什么?你能指点我关于这个主题的任何参考资料,还是只是你随着时间习惯的东西?
我正在用.NET编写一个应用程序,它将根据一些输入生成随机文本.所以,如果我有文字,"I love your {lovely|nice|great} dress"我想随机选择lovely/nice/great并在文本中使用它.欢迎使用C#或VB.NET中的任何建议.
我有一个SSIS项目,我正在构建一个基于某些变量的SQL命令.我正在脚本任务中构造命令,并希望将构造的SQL输出到"执行结果"窗口.我试图使用我的脚本内部的FireInformation行执行此操作,如下所示:
Dts.Events.FireInformation(99, "test", "Make this event appear!", "", 0, true);
Run Code Online (Sandbox Code Playgroud)
但是,在脚本编辑器中编辑ScriptMain.cs时,该行以红色下划线,并且在鼠标悬停时,我收到以下消息:
错误:
'Microsoft.SqlServer.Dts.Tasks.ScriptTask.EventsObjectWrapper.FireInformation(int,string,string,string,int,ref bool')的最佳重载方法匹配包含一些无效参数
结果,我的脚本无法编译,我无法执行它.
知道我在这里做错了什么,或者我需要改变什么才能在执行输出中看到我的变量的值?
我有一个处理HTTP请求的Web服务.它接收的文档具有嵌入的DOCTYPE,用于指定.dtd文件.我希望使用更新的XML架构验证文件,以便在较新的设备连接到我的服务时制作.
我可以成功忽略.dtd文件中的验证,但.dtd文件必须存在于我的本地硬盘驱动器上.我想删除这些过时的文件,并没有找到办法.
我正在处理的示例XML文档:
<?xml version="1.0" encoding="us-ascii" standalone="no"?>
<!DOCTYPE SomeMessage SYSTEM "SomeMessage.dtd">
<SomeMessage>data</SomeMessage>
Run Code Online (Sandbox Code Playgroud)
我用来打开文档的功能:
private void LoadXmlDoc(XmlTextReader myXmlTextReader)
{
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.Schemas.Add(null, MyGoodSchemaFile);
readerSettings.DtdProcessing = DtdProcessing.Ignore;
readerSettings.XmlResolver = null; // Added as a test.
readerSettings.ValidationEventHandler += ValidationEventHandle;
XmlReader myXmlReader = XmlReader.Create(myXmlTextReader, readerSettings);
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.XmlResolver = null; // Added as a test.
myXmlDocument.Load(myXmlReader); // Exception thrown here!
}
Run Code Online (Sandbox Code Playgroud)
捕获的异常:
System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\SomeMessage.dtd'. File name: 'c:\windows\system32\inetsrv\SomeMessage.dtd' at System.IO.__Error.WinIOError(Int32 errorCode, String …
这两种方法有什么区别?
第一:
public static int Foo<T>(T first, T second) where T:IComparable
{
return first.CompareTo(second)
}
Run Code Online (Sandbox Code Playgroud)
第二:
public static int Foo(IComparable first, IComparable second)
{
return first.CompareTo(second);
}
Run Code Online (Sandbox Code Playgroud) 假设我有一个自动实现的属性
public int SheetNum { get; set; }
Run Code Online (Sandbox Code Playgroud)
无论如何都要将默认值设置SheetNum为1,所以它会是这样的
private int sheetNum = 1;
public int SheetNum
{
set { this.sheetNum = value; }
get { return this.sheetNum; }
}
Run Code Online (Sandbox Code Playgroud)