我正在为我的网站开发一个Web API,并遇到了一个问题.
目前,API应该返回指定用户的详细信息.
这是我的帐户控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Http;
using System.Net;
using RoditRepoAPIV2.Models;
namespace RoditRepoAPIV2.Controllers
{
public class AccountController : Controller
{
Account[] products = new Account[]
{
//accounts will be added...
};
public IEnumerable<Account> GetAllAccounts()
{
return products;
}
public IHttpActionResult GetAccount(int id)
{
var account = products.FirstOrDefault((p) => p.Id == id);
if (account == null)
{
return NotFound();
}
return Ok(account);
}
}
}
Run Code Online (Sandbox Code Playgroud)
尽管此处的大部分代码都是从教程中复制的,但Visual Studio却抱怨当前上下文中不存在NotFound()"和" Ok(account) …
在Java中,我将如何执行以下操作:
Foo bar = new Foo();
Foo a = bar;
Foo b = bar;
bar = null;//will only set bar to null. want to set value of bar to null rather than the reference to null.
Run Code Online (Sandbox Code Playgroud)
是否可以设置变量bar,a并且b(都是引用bar)仅在访问bar时为null?如果是这样,有人可以解释如何这样做.
我是C#的新手,但我从VB.Net那里学到了很多关于.Net for windows编程的知识.
我刚刚创建了一个简单的SMTP客户端,它从程序中发送电子邮件.它是一个控制台应用程序,一次只能通过服务器发送一封电子邮件.这是很慢的,我需要在通过我的客户端发送多封电子邮件同时.
这可能在C#中吗?
信息
我一直在用 c# 开发一个 web http 服务器,并决定添加一个远程控制台功能。控制台可以从任何位置使用,并使用 TcpListener(Web 服务器)和 TcpClient(远程控制台)来发送命令和函数。
编码
这是我的服务器的样子:
TcpListener consoleListener = new TcpListener(consolePort);
consoleListener.Start();
byte[] bytes = new Byte[256];
string data = null;
while (true)
{
TcpClient client = consoleListener.AcceptTcpClient();
data = null;
byte[] msg = { 0 };
int i;
while ((i = client.GetStream().Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
if (data == "shutdown")
{
//Server shutdown logic.
}
//Other commands here...
else
{
msg = Encoding.ASCII.GetBytes("Invalid command. Type 'help' or …Run Code Online (Sandbox Code Playgroud) 我最近一直在研究一些多线程控制台应用程序,并想知道如何做到这一点.我使用此代码来控制应用程序创建的线程数量:
foreach(string s in File.ReadAllLines("file.txt")){
while (threads >= maxThreads) ;
Thread t = new Thread(() => {
threads++;
//thread code - make network request using 's'
Console.WriteLine("TEST");
threads--;
Thread.CurrentThread.Abort();
});
t.start();
}
Run Code Online (Sandbox Code Playgroud)
但是,由于while循环,Console.WriteLine创建的方法被阻止,并且在下一个空闲线程可用之前不会显示.
有什么方法可以防止这种阻止Console.WriteLine呼叫的循环吗?
编辑 - while循环中的反转条件.
我最近一直在为Android开发游戏.该游戏的格式与经典的口袋妖怪游戏相似(非常复杂).我有很多没有任何问题.但是,我发现当有人说话时,很难开发出现在屏幕底部的对话(打字机文本)框.我坚持等待任何输入而不阻止渲染和更新方法(因为它们都在同一个线程上运行).
这是我的游戏循环的简化版本,概述了结构以及我每帧的作用.显示的更新方法通过View#onDraw方法调用.
public static void update(Canvas canvas, GameView view){
//time operations (calculating delta etc.)
long cTime = System.currentTimeMillis();
delta = cTime - time;
time = cTime;
globals.put("time", time);
globals.put("delta", delta);//set vars for scripts
camera.applyToCanvas(canvas);//apply camera matrix to canvas
if(map != null)map.update();
if(battle != null)map.update();
Effect.updateAll();//update everything (game logic)
render.load(canvas);//load the canvas into my custom render engine
render();//call render method (shown below)
view.invalidate();//reset view for redraw
}
public static void render(){
render.reset();//clears the canvas using canvas.setColor(Color.BLACK)
if(map != null)map.draw();
if(battle != …Run Code Online (Sandbox Code Playgroud) 我最近决定开始学习基本的python ...我正在创建一个简单的python File类,类似于.NET框架中使用的类.
到目前为止,我有以下代码:
import os
class File:
def __init__(self, filename=""):
self.path = filename
self.pathwithoutfilename, self.extwithdot = os.path.splitext(filename)
self.ext = self.extwithdot.replace(".", "")
def exists():
rbool = False
if(os.path.exists(self.path)):
rbool = True
else:
rbool = False
return rbool
def getPath():
return self.path
test = File("/var/test.ad")
print(test.path)
print(test.extwithdot)
print(test.ext)
print(test.getPath)
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,(我在Ubuntu上使用python 2.7)它会为test.getPath函数打印它:
<bound method File.getPath of <__main__.File instance at 0x3e99b00>>
Run Code Online (Sandbox Code Playgroud)
我一直在改变和编辑我的代码一段时间但我没有取得任何成功...我希望getPath函数返回self.path之前设置的值...
谢谢
Rodit
c# ×4
java ×2
.net ×1
android ×1
asp.net-mvc ×1
email ×1
game-engine ×1
python ×1
python-idle ×1
reference ×1
smtp ×1
tcpclient ×1
tcplistener ×1