假设有一个名为A的类,其方法如下:
public void SomeMethod<T>(ref T para1)
{
...
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个接口(让我们称之为ITest)强制执行一个方法(让我们称之为RequiredMethod())并且有一堆实现此接口的类.
在SomeMethod的声明中,我怎么能提到T需要实现ITest以便我可以做这样的事情?
public void SomeMethod<T implements ITest>(ref T para1)
{
...
para1.RequiredMethod();
...
}
Run Code Online (Sandbox Code Playgroud) 我找不到任何有关如何正确计算 c# 的 ProcessorAffinity 上的亲和力设置的文档。
我正在传递选定核心的列表并添加它们以获得最终的亲和力设置,但是我的计算似乎已关闭。
如何根据所选核心 (0-32/64) 的列表正确计算亲和力。
另外这该如何优化呢?
if (!string.IsNullOrEmpty(affinitystr) && !affinitystr.Equals("-1"))
{
string[] words = affinitystr.Split(',');
int affinitytotal = 0;
foreach (string word in words)
{
int affinity = Convert.ToInt32(word);
if (affinity == 0) { affinity = 1; } // core 0
else if (affinity == 1) { affinity = 2; } // core 1
else if (affinity == 2) { affinity = 4; } // core 2
else if (affinity == 3) { affinity = 8; …Run Code Online (Sandbox Code Playgroud) 所以,我有一个类GameObject,我用它作为许多子类的基础.
class GameObject()
{
blah;
}
class AmmoBox() : Gameobject()
{
different blah;
}
class Taco() : GameObject() {very different blah;}
Run Code Online (Sandbox Code Playgroud)
后来我在列表中使用它们,我想为每个子类指定不同的更新/ etc行为.
foreach (AmmoBox a in GameObjects) { }
foreach (Taco t in GameObjects) { }
Run Code Online (Sandbox Code Playgroud)
编译器抛出错误"无法将'GameObject'类型的对象强制转换为'AmmoBox'.我知道这是一个可怜的错误,我该怎么做呢?
我已经尝试过很难用之前的类似答案来解决这个问题,但我仍然无法看到我的问题,希望你能提供帮助.我的代码看起来像这样:
String MyContent =" ";
String nextline = " ";
InputStream in = new FileInputStream(f);
BufferedInputStream bin = new BufferedInputStream(in);
DataInputStream din = new DataInputStream(bin);
while(din.available()>1)
{
nextline = din.readLine();
//Filter out XML headers which are not browser compliant
if (nextline.length > 4)
{
if (nextline.substring(1,5) != "<?xml")
{
MyContent=MyContent+ nextline;
}
}
}
out.print (MyContent);
in.close();
bin.close();
din.close();
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
An error occurred at line: 25 in the jsp file: /MaxiSunReports/DisplayXMLFile.jsp
nextline.length cannot be resolved or is not a field …Run Code Online (Sandbox Code Playgroud) 我想为数据相关代码创建单元测试.例如:
具有通常的创建,更新和删除的用户类.
如果我想为"用户已存在"方案创建测试,或者更新或删除测试.我需要知道我的数据库中已存在特定用户.
在这种情况下,对于可以按任何顺序运行的这些操作进行独立测试的最佳方法是什么?
我在C#中有一个具有当前属性的对象.
public DateTime startDate
{
get
{
string[] ymd = Environment.GetCommandLineArgs()[2].Split('.');
return new DateTime(Int32.Parse(ymd[2]), Int32.Parse(ymd[1]), Int32.Parse(ymd[0]));
}
set { startDate = value; }
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用定义为此的函数时:
public String Calculate(){
if (startDate > endDate)
return "not calculable since the end date can not be before than the start date.";
while (startDate <= endDate)
{
if (startDate.DayOfWeek.ToString()[0] != 'S')
count++;
startDate = startDate.AddDays(1);
}
return "not implemented yet";
Run Code Online (Sandbox Code Playgroud)
Stack Overflow发生:)你可以帮我解决这个问题吗?
此代码将电子邮件发送到访问数据库中保存的多个电子邮件地址,但我在line(email =read_Email.GetValue(i).ToString();)中遇到问题不能隐式地将类型'string'转换为'int'
任何帮助.
try
{
ArrayList list_emails = new ArrayList();
int i = 0, email = 0;
connection.Open(); //connection to the database.
OleDbCommand cmd_Email = new OleDbCommand("Select Email from Email_Table", connection);
OleDbDataReader read_Email = cmd_Email.ExecuteReader();
while (read_Email.Read())
{
email =read_Email.GetValue(i).ToString();
list_emails.Add(email); //Add email to a arraylist
i = i + 1 - 1; //increment or ++i
}
read_Email.Close();
connection.Close(); //Close connection
foreach (string email_to in list_emails)
{
MailMessage mail = new MailMessage();
mail.To.Add(email_to);
mail.Subject = label2.Text + " …Run Code Online (Sandbox Code Playgroud) 我正在研究Google Calendar API的.net版本的包装器.身份验证非常简单,在本地工作正常(localhost:port).
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "The id of my public website",
ClientSecret = "The secret of my public website",
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None).Result;
// Create the service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential
});
return service.Events.List("primary").Execute().Items;
Run Code Online (Sandbox Code Playgroud)
但问题是,当相同的代码部署到生产环境时(当然,密码已更改),只要我尝试访问数据,应用程序就会挂起.没有例外,没有错误代码,它只是永远加载.
有没有人经历过这个?
我有覆盖primefaces lazydatamodel加载的问题.加载方法的错误点.我正在使用primefaces 5.0.在Jboss Developer Studio 7.1中工作
private LazyDataModel<City> mdlCityList;
@PostConstruct
public void init() {
try {
this.mdlCityList = new LazyDataModel<City>() {
private static final long serialVersionUID = 1L;
@Override
public List<City> load(int first, int pageSize,
String sortField, SortOrder sortOrder,
Map<String, String> filters) {
mdlCityList.setRowCount(cityFacade.count(filters));
return cityFacade.getResultList(first, pageSize, sortField,
sortOrder, filters);
}
};
mdlCityList.setRowCount(cityFacade
.count(new HashMap<String, String>()));
} catch (Exception e) {
System.out.println("Exception in CityListProducer " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我正在实现@Override,但它仍然指出:
new LazyDataModel(){}类型的方法load(int,int,String,SortOrder,Map)必须覆盖或实现超类型方法
我有这个 c# MVC 代码,它与 GetAsync 和 GetPost 方法一起工作得很好,但是当使用 GetStringAsync 时,它在该行冻结:
version = await client.GetStringAsync("/API/Version");
Run Code Online (Sandbox Code Playgroud)
驱动程序代码:
Task<string>[] tasks = new Task<string>[count];
for (int i = 0; i < count; i++)
{
tasks[i] = MyHttpClient.GetVersion(port, method);
}
Task.WaitAll(tasks);
string[] results = new string[tasks.Length];
for(int i=0; i<tasks.Length; i++)
{
Task<string> t = (Task<string>)(tasks[i]);
results[i] = (string)t.Result;
}
Run Code Online (Sandbox Code Playgroud)
HttpCilent 代码:
public static async Task<string> GetVersion(int port, string method)
{
try
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:" + port);
string version …Run Code Online (Sandbox Code Playgroud) c# ×8
asp.net ×1
database ×1
dependencies ×1
email ×1
generics ×1
google-api ×1
httpclient ×1
interface ×1
java ×1
jsf ×1
jsf-2 ×1
list ×1
ms-access ×1
oauth ×1
primefaces ×1
properties ×1
setter ×1
string ×1
subclass ×1
unit-testing ×1
vb.net ×1
xna ×1