我有3个字符串,这些不是真正的数据只是一个例子:
string items = "Item 1, Item 2, Item 3";
string price = "300, 400, 500";
string tax = "30, 50, 60";
Run Code Online (Sandbox Code Playgroud)
我想要做的是创建一个这样的数组:
[Item 1] => Array([Price] => 300, [Tax] => 30), [Item 2] => Array([Price] => 400, [Tax] => 50), [Item 3] => Array([Price] => 500, [Tax] => 60)
Run Code Online (Sandbox Code Playgroud)
问题是我不知道如何在ASP.NET中执行此操作,如果我必须在PHP中执行此操作,这将没有问题.
我是ASP.NET MVC和C#的新手,我正在编写一个控制器来传递构建列表所需的信息
Organization 1
Organization 1 - Category 1
Organization 1 - Category 2
Organization 2
Organization 2 - Category 1
Organization 2 - Category 2
Organization 2 - Category 3
Organization 3
Organization 3 - Category 1
Run Code Online (Sandbox Code Playgroud)
所有这些行都是字符串.换句话说,我需要将每个组织与该组织的类别列表相关联.截至目前,这些组织和类别存在于数据库表中,但是当我提取它们时,我需要将它们放在"正确的"C#数据结构中以传递给我的View.
显然我可以做点什么
public struct orgcats
{
string org;
List<string> cats;
}
List<orgcats> oclist;
Run Code Online (Sandbox Code Playgroud)
并附加oclist并传递,但我相信你们中的一个人知道更好的方式并且可以教育我.我希望我的代码具有完美的紧凑性,效率,聪明,可读性和正确性.
尝试使用预定义的样式来样式化表,但是没有任何效果。我尝试了一个新创建的文档和一个从保存的模板创建的文档。使用SDK Productivity工具,我可以看到模板中有样式,但尚未应用。我尝试添加样式或直接设置样式,但似乎都没有用。
public static void CreateWordprocessingDocument(string fileName) {
string[,] data = {
{"Texas", "TX"},
{"California", "CA"},
{"New York", "NY"},
{"Massachusetts", "MA"}
};
using (var wordDocument = WordprocessingDocument.Open(fileName, true)) {
// We need to change the file type from template to document.
wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document);
var body = wordDocument.GetDocument().Body;
Table table = new Table();
TableProperties props = new TableProperties();
TableStyle tableStyle = new TableStyle { Val = "Light Shading Accent 1" };
props.TableStyle = tableStyle;
//props.Append(tableStyle);
table.AppendChild(props);
for (var i = 0; i …Run Code Online (Sandbox Code Playgroud) 全新的C#[4小时新:)],但希望有一些关于Board Feet Calculator的指针,将用户输入仅限制为数字,不允许使用字母或特殊字符.
首先,限制是在类,方法和/或程序中进行的吗?(我相信课程和方法)
其次,我在下面看到了一个例子,我会使用类似的东西吗?
第三,如果是这样,我是否需要为KeyPress和KeyPressEventArgs创建单独的类?(我相信他们自动在那里,例如
public char KeyChar { get; set; }
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// allows only letters
if (!char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
Run Code Online (Sandbox Code Playgroud)
我的计划
namespace BoardFt_MyTry_
{
class Program
{
static void Main(string[] args)
{
Board board = new Board();
board.lengthOfboard = Convert.ToDouble(askQuestion("What is the length of your board in inches?"));
board.widthOfboard = Convert.ToDouble(askQuestion("What is the width of your board in inches?"));
board.thicknessOfboard = Convert.ToDouble(askQuestion("What is the thickness of your board …Run Code Online (Sandbox Code Playgroud) 我在 ASP.NET 中有一个像这样的控制器:
public class FileUploadController : Controller
{
// ...
static List<ThreePartKey> uploadedFiles = new List<ThreePartKey> ();
// ...
public ActionResult Index ( )
{
// ...
}
[HttpPost]
public ActionResult Index (HttpPostedFileBase file,
string selectedOrgName,
string selectedCatName)
{
// ...
uploadedFiles.Add(new ThreePartKey {
orgname = selectedOrgName,
catname = selectedCatName,
filename = fileNameNoExtension });
ViewBag.uploadedFiles = uploadedFiles;
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
其中第二个Index函数上传用户选择的文件并将其信息添加到已上传文件的列表中。该列表信息用于构建 HTML 表格。List<ThreePartKey> uploadedFiles我最终添加前缀的原因static是因为如果没有它,我的列表将只有每次调用时最后上传的文件Index。
该列表在内存中保留多长时间?我希望它与 user 相对应sessions,但我不确定。
[XmlElement(ElementName = ElementConstants.CreateDate,
Namespace = "http://api.facebook.com/1.0/",
DataType = "date", Type = typeof(DateTime))]
public DateTime CreateDate { get; set; }
Run Code Online (Sandbox Code Playgroud)
如果我尝试在属性中取出DataType:{"字符串'1233469624'不是有效的AllXsd值."}
以下是其中一个节点值的示例:
<created>1230437805</created>
Run Code Online (Sandbox Code Playgroud)
我不知道如何在这里设置DateTime属性,以便成功反序列化.
我正在尝试编写一些代码来帮助单元测试WCF服务.这些服务通过创建代理实例的facade类访问,然后调用代理方法并返回结果; 对于每种代理方法.我希望能够用创建真实服务或虚假服务的东西替换当前的创建代码.
我无法让它工作.我把它归结为以下内容:
using System.ServiceModel;
namespace ExpressionTrees
{
public interface IMyContract
{
void Method();
}
public class MyClient : ClientBase<IMyContract>, IMyContract
{
public MyClient()
{
}
public MyClient(string endpointConfigurationName)
: base(endpointConfigurationName)
{
}
public void Method()
{
Channel.Method();
}
}
public class Test
{
public TClient MakeClient<TClient>()
where TClient : ClientBase<IMyContract>, IMyContract, new()
{
return new MyClient("config");
// Error:
// Cannot convert expression of type 'ExpressionTrees.ServiceClient' to return type 'TClient'
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么即使MyClient该类派生ClientBase<IMyContract>并实现IMyContract,我也无法 …
我想表现出TimeSpan的MessageBox,但我得到一个错误:
DateTime date1 = new DateTime(byear, bmonth, bday, 0, 0, 0);
DateTime datenow = DateTime.Now;
TimeSpan age = datenow - date1;
MessageBox.Show(ToString(age));
Run Code Online (Sandbox Code Playgroud)
Error 1 No overload for method 'ToString' takes '1' arguments
我如何输出消息框TimeSpan?
您是否可以提供JavaScript函数示例,以便从Web浏览器启动计算机上安装的应用程序(例如Google Chrome 4).特别是如果.Net APPs有任何特殊的简化这个过程apis,这些人员有一些libs,请与我们分享链接.
那么如何在启动程序中创建并存储一个小型本地服务器,该服务器可以处理一些本地URL,如http:// localhost/maAppServer/MyAppCalculator/Start,用于启动已在其配置文件中写入其名称和本地URL的应用程序安装?
那么如何从Web浏览器启动C#.NET app\program?
我正面临这个问题
class person
{
;
}
person p = new person();
XmlSerializer ser = new XmlSerializer(p.GetType());
FileStream fs = File.Open("sam.xml",FileMode.OpenOrCreate, FileAccess.Write);
ser.Serialize(fs,p)
fs.flush();
fs.close();
FileStream stream = FileStream("sam.xml", FileMode.Open);
XmlDictionaryReader xdr = XmlDictionaryReader.CreateTextReader(stream,new XmlDictionaryReaderQuotas());
Run Code Online (Sandbox Code Playgroud)
现在我的问题是如何在不创建xml文件的情况下创建xdr对象.
c# ×10
asp.net ×3
.net ×2
asp.net-mvc ×2
browser ×1
docx ×1
filestream ×1
generics ×1
javascript ×1
messagebox ×1
mocking ×1
ms-word ×1
openxml ×1
session ×1
timespan ×1
validation ×1
wcf ×1
xml ×1