[英]Running a .NET Core Console Application
I am trying to create a console app from a project template, but I am running into multiple bugs.我正在尝试从项目模板创建控制台应用程序,但我遇到了多个错误。
Can someone please create a console app and explain what information I need to change in order for it to run?有人可以创建一个控制台应用程序并解释我需要更改哪些信息才能运行它吗? It should be very simple.
应该很简单。
Link: https://medium.com/@utterbbq/c-serializing-list-of-objects-to-csv-9dce02519f6b链接: https://medium.com/@utterbbq/c-serializing-list-of-objects-to-csv-9dce02519f6b
Summary:概括:
I am unsure if I am supposed to insert values into these property types or to leave blank.我不确定是否应该将值插入这些属性类型或留空。 I believe this half is similar to filling out a model form?
我相信这半部分类似于填写 model 表格?
void Main()
{
var rentInvoiceType = typeof(ClientClass);
var properties = typeof(ClientClass).GetProperties()
.Where(n =>
n.PropertyType == typeof(string)
|| n.PropertyType == typeof(bool)
|| n.PropertyType == typeof(char)
|| n.PropertyType == typeof(byte)
|| n.PropertyType == typeof(decimal)
|| n.PropertyType == typeof(int)
|| n.PropertyType == typeof(DateTime)
|| n.PropertyType == typeof(DateTime?));
For the last half, I am receiving errors under the 'var output' value, 'var delimiter' value, the instance if the 'items' in item, 'null', the value of 'n', and '.Aggregate'.在后半部分,我在“var output”值、“var delimiter”值、item 中的“items”实例、“null”、“n”的值和“.Aggregate”下收到错误。
var output = “”;
var delimiter = ‘;’;
using (var sw = new StringWriter())
{
var header = properties
.Select(n => n.Name)
.Aggregate((a, b) => a + delimiter + b);
sw.WriteLine(header);
foreach (var item in items)
{
var row = properties
.Select(n => n.GetValue(item, null))
.Select(n => n == null ? “null” : n.ToString())
.Aggregate((a, b) => a + delimiter + b);
sw.WriteLine(row);
}
output = sw.ToString();
}
return output;
I am receiving errors under the 'var output' value,
我在“var output”值下收到错误,
From the example, you need to replace single ( ' ' ) and double ( “ ” ) quotes with ( ' ' ) and ( " " ).从示例中,您需要将单引号 ( ' ' ) 和双引号 ( “ ” ) 替换为 ( ' ' ) 和 ( " " )。
and '.Aggregate'
和 '.Aggregate'
Add:添加:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq; // <=
I am unsure if I am supposed to insert values into these property type
我不确定是否应该将值插入这些属性类型
Put your values in the class you have defined (not in the 'PropertyType'):将您的值放入您定义的 class 中(不在“PropertyType”中):
var rentInvoice = new RentInvoice()
{
Car = "Lotus",
Price = 1234,
...
};
the instance if the 'items' in item,
如果项目中的“项目”的实例,
And add the class to 'items':并将 class 添加到“项目”:
var items = new List<RentInvoice>();
items.Add(rentInvoice);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.