我想将此JSON映射到.NET类.如何将此JSON数据映射到类中?请建议如何.这是json:
{"results": [
"43853",
"43855",
"43856",
"43857",
{
"questionType": 3,
"choiceAnswers": [123]
}
]}
Run Code Online (Sandbox Code Playgroud) 我是 c# 新手,我想在 Web API 中将模型类对象转换为 DataTable。
模型类
public class Employee_Master_Model
{
public string UserType { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
public string Mobile { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public bool IsActive { get; set; }
public int EmployeeId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public async Task<IActionResult> …Run Code Online (Sandbox Code Playgroud) 如何使用整数值确定星期几,而另一个整数确定星期几?例如,如果今天是(为星期天输入一个类似0的整数),而我则输入整数2,则其为星期二。这是我到目前为止的代码:
namespace DayOfTheWeek
{
class Program
{
static void Main(string[] args)
{
int Sunday=0;
int Monday = 1;
int Tuesday = 2;
int Wednesday = 3;
int Thursday = 4;
int Friday = 5;
int Saturday = 6;
Console.WriteLine("Today is " + 0);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我真的很为难。
我有两个微服务。第一项服务为客户,第二项服务为发票服务。
在 Invoice MicroService 中,我将仅保存 CustomerId。使用此 CustomerId,我想检索客户微服务的所有相关数据。但我不知道异步通信。
请给我一些想法。
c# asp.net-core-mvc microservices asp.net-core asp.net-core-webapi
我有一个关于公共和静态方法的问题。我是 C# 编码新手,我知道公共方法只能使用对象来访问。但是,静态方法可以在没有类对象的情况下进行访问。但是使用公共方法有什么意义呢?为什么不总是使用静态方法呢?
我一直在使用 Visual Studio Forms 创建一个大学课程应用程序,我试图启动我制作的表单来检查它是否连接到其背后的数据库,但它不会接受表单的名称合法的。我不知道为什么,因为它出现在解决方案资源管理器中。
这是program.cs的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FoxhillCustomer
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmViewEditStaff());
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是 frmViewEditStaff.cs 的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FoxhillViewEditStaff
{
public partial class frmViewEditStaff : Form …Run Code Online (Sandbox Code Playgroud) 我有一个函数来返回类实例.这里是:
public class Warrior{
private Type GetSpec()
{
if ((WarriorSpecs)charData.CharacterSpec == WarriorSpecs.Barbarian)
{
return new Barbarian(charData).GetType();
}
if ((WarriorSpecs)charData.CharacterSpec == WarriorSpecs.Guardian)
{
return new Guardian(charData).GetType();
}
if ((WarriorSpecs)charData.CharacterSpec == WarriorSpecs.Knight)
{
return new Knight(charData).GetType();
}
return this.GetType();
}
}
Run Code Online (Sandbox Code Playgroud)
所有这些类Barbarian,Guardian,Knight是类的子类Warrior.
我的问题是为什么我不能做到以下几点:
public void FunctionInWarriorClass(){
GetSpec.AnotherVoidInWarriorClass();
}
Run Code Online (Sandbox Code Playgroud)
我想要的只是GetSpec返回任何子类的实例,然后调用在Warrior类中声明的函数.这甚至可能吗?
List的Add和Insert操作有什么区别?
List<Tuple<int,string>> samplelinq = new List<Tuple<int, string>>();
Run Code Online (Sandbox Code Playgroud)
这里我想要列出一个元组。我应该使用添加还是插入。
我正在尝试在MONGODB中创建一个通用的“ GET”。但是它不会转换错误:
不能隐式转换类型
我的服务
namespace AdmissionAnonymousForm.Infrascructure.Services
{
public class BankService: IBankService
{
private readonly IMongoCollection<Bank> _bank;
public BankService(IConfiguration config)
{
var client = new MongoClient(config.GetConnectionString("AdmissionAnonymous"));
var database = client.GetDatabase("AdmissionAnonymous");
_bank = database.GetCollection<Bank>("Bank");
}
public Task<Bank> Get()
{
return _bank.Find(bank => true).ToListAsync();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的模特
namespace AdmissionAnonymousForm.Infrascructure.Services.Core
{
public interface IBankService
{
Task<Bank> Get();
Task<Bank> Get(Guid id);
Task<Bank> Post(Bank bank);
void Update(Guid id, Bank addressIn);
void Delete(Guid id);
}
}
Run Code Online (Sandbox Code Playgroud) 这给定的代码行。如何以更优化的方式编写?下面的代码工作正常,但我需要另一种写法
var attachments = new List<Attachments>();
foreach (var attachment in msg.attachments) //msg.attachments is a Dictionary<string, FileAttachment> type
{
var attach = new Attachments();
attach.name = attachment.Value.name;
attach.type = attachment.Value.type;
attachments.Add(attach);
}
Run Code Online (Sandbox Code Playgroud) 所以,基本上,我试图在我的文本 rpg 中创建一个保存点。我想通过使用 .txt 文件并以这种方式跳转到每个方法来做到这一点。但是,当我尝试输入文件的路径和字符串内容时,它返回 CS0029 错误并指出它无法将 void 转换为字符串。
public void PickingUpScroll()
{
savePoint = "PickingUpScroll";
saveData = File.WriteAllText(savePath, savePoint);
hasFireMagic = true;
Console.WriteLine("You approach the strange scroll in your room and pick it up. A strange light eminates from the foreign symbols on the paper. You feel a warmth in your hands.\nLooking down, you notice they are glowing with a strange light, almost like fire.");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("You have accquired 'Fire Magic'");
Console.ForegroundColor = ConsoleColor.White;
if (hasWeapons == …Run Code Online (Sandbox Code Playgroud) 所以我从一个 API 中接收到 int 的数量,我使用这样的:1000和1235,其实际数量是10.00和12.35
所以我想将 int 数字转换为十进制形式,我将如何在 c# 中做到这一点?
例子:
850 > 8.50 8500 > 85.00 90002 > 900.02 136789 > 1367.89
我有简单的函数检查字符串是否是数字。突然我发现它不能与“0”或“00”一起使用。请告诉我为什么!以及如何让它发挥作用?
string num = "00";
Int32.TryParse(num, out int n);
if (n > 0) return true; // It works nice on any digits except 0 and 00.
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
double.TryParse(num, out double n);
Run Code Online (Sandbox Code Playgroud)
但也不要工作。
所以我就这样去了:
if ((n > 0) | (num == "0") | (num == "00")) return true;
Run Code Online (Sandbox Code Playgroud)