我有一个界面
using ClassAbstractFactory;
public interface IPlugin
{
AbstractFactory GetFactory();
}
Run Code Online (Sandbox Code Playgroud)
和一个AbstractFactory
public abstract class AbstractFactory
{
public abstract AbstractCake CreateCake();
public abstract AbstractBox CreateBox();
}
public abstract class AbstractCake
{
public abstract void Interact(AbstractBox box);
}
public abstract class AbstractBox
{
}
Run Code Online (Sandbox Code Playgroud)
我有继承AbstractCake的.dll
public class ChocolateCake : AbstractCake
{
private bool _isPacked;
private bool _isDecorated;
private string _nameOfCake;
public ChocolateCake()
{
_isPacked = false;
_isDecorated = false;
_nameOfCake = "??????????";
}
public bool IsPacked
{
get { return _isPacked; } …Run Code Online (Sandbox Code Playgroud) 我是Entity Framework的新手.我正在使用现有数据库,并且表没有定义主键.当我使用Entity Framework时,我得到错误"表/视图'没有定义主键.已经推断出密钥,并且定义被创建为只读表/视图.".我查了几个堆栈溢出解决方案/谷歌,我还有一些问题,
谢谢,
完全披露:这是一项家庭作业.我不是在寻找讲义,只是指导,因为我被卡住了.
我试图将一个月和一天(都是int)转换为"月/日"的字符串表示.这就是我到目前为止所拥有的.
我无法弄清楚的是如何在月和日之间以"/"返回日期.
public string toString()
{
string month = myMonth.ToString();
string day = myDay.ToString();
string date = month "/" day; // I know this won't work. I just wanted to give a visual of what I want the final result to look like.
/// so today would be ' 11/11 ' tomorrow ' 11/12 '
return date;
}
Run Code Online (Sandbox Code Playgroud)
注意:此方法不会打印仅创建它的结果.
我对LINQ相对较新,但正在寻找一些关于如何处理以下内容的"最佳实践"建议.我知道有很多方法可以解决这个问题,但是看看有经验的人会如何编写代码.
我的LINQ目前:
var company = (from c in db.RPTINQUIRies
where c.CONCOM == concom && c.LOPER == engineer
orderby c.CREATION_DATE descending
select c);
Run Code Online (Sandbox Code Playgroud)
现在,ActionResult在这里(工程师)传递的参数可能是空的也可能不是.如果它是空的,我基本上想要一起删除该&& C.LOPER == engineer条款.
处理这个问题的最佳方法是什么?
我有两个名为barcodesSource和barcodesTarget的通用集合.它们都是同一类型的助手.我想比较名为barcodesSource的集合和基于属性BARCODE的第二个集合,并仅返回第一个集合中的数据,这些集合在第二个集合中没有相应的BARCODE.
任何人都可以告诉我这个解决方案吗?
class Helper
{
public long BARCODE { get; set; }
public int ITEM { get; set; }
}
List<Helper> barcodesSource = new List<Helper>();
List<Helper> barcodesTarget = new List<Helper>();
var distinctBarcodes = barcodesSource.Where(a => barcodesTarget.All(b => b.BARCODE != a.BARCODE));
Run Code Online (Sandbox Code Playgroud) 我发现如何使用此查询确定哪些列是给定表的主键列:
SELECT CONSTRAINT_NAME, COLUMN_NAME
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE TABLE_NAME='tablename_here' AND
CONSTRAINT_NAME LIKE 'PK_%'
Run Code Online (Sandbox Code Playgroud)
我可以通过使用此查询找到身份种子和增量:
SELECT IDENT_SEED('tablename_here'), IDENT_INCR('tablename_here')
Run Code Online (Sandbox Code Playgroud)
我无法使用约束信息,因为主键约束可以跨多个列.我似乎无法找到任何Transact SQL函数来提供我的身份信息.
有人可以帮我理解如何找到身份信息吗?
我正在使用SQL Server 2000.
如何使用带有匿名类型的select new关键字将linq更新为sql值,因为我使用了var关键字并选择了我需要的新查询但是它返回了这样的错误
编译器错误消息:CS0200:属性或索引器'AnonymousType#1.Code'无法分配 - 它是只读的
这是我的代码:
var ProjectView12 = (from x in db.Projects
select new
{
add = db.Locations.Where(y = > y.ID == x.RegionID).FirstOrDefault().Name,
Province = db.Locations.Where(y = > y.ID == x.ProvinceID).FirstOrDefault().Name,
District = db.Locations.Where(y = > y.ID == x.DistrictID).FirstOrDefault().Name,
Code = x.Code,
Name = x.Name,
ProjectIdentificationDate = db.Milestones.Where(y = > y.ProjectID == x.ID && y.StageID == 1 && y.ComponentID == 1 && y.ModuleID == 1).FirstOrDefault().Date.ToString(),
ProjectLat = Convert.ToDecimal(x.Lat),
ProjectLong = Convert.ToDecimal(x.Lon),
Remarks = db.Milestones.Where(y = > y.ProjectID …Run Code Online (Sandbox Code Playgroud) 我正在使用下面的代码将字符数组转换为字符串C.但是输出与我的预期不同.
#include<stdio.h>
int main()
{
char data[5] = {
'a', 'b', 'c', 'd', '\0'
};
char buff[100];
int i = 0;
while (data[i] != '\0')
{
printf("%c Character here \n", data[i]);
snprintf(buff, 100, "%s", & data[i]);
printf("%s String here\n", buff);
i++;
}
}
Run Code Online (Sandbox Code Playgroud)
我期望的结果是
a Character here
a String here
b Character here
b String here
c Character here
c String here
d Character here
d String here
Run Code Online (Sandbox Code Playgroud)
但是我把它作为输出
a Character here
abcd String here
b Character here
bcd String …Run Code Online (Sandbox Code Playgroud) public partial class Form1: Form {
// Define a few variables
int InputInteger;
int HoldInteger;
int OutputInteger;
public Form1() {
InitializeComponent();
}
private void exitBtn_Click(object sender, EventArgs e) {
//Used to close the form when exit is clicked
this.Close();
}
private void clearBtn_Click(object sender, EventArgs e) {
//this will deselect all of the radio buttons, along with clearing the
// textboxes with input and output information.
depositBtn.Checked = false;
checksBtn.Checked = false;
serviceBtn.Checked = false;
inputTxt.Clear();
outputTxt.Clear();
}
private void …Run Code Online (Sandbox Code Playgroud) 抱歉标题不好.我目前正在学习TPL并阅读这篇博客文章
异步调用同步方法的能力对可伸缩性没有任何作用,因为如果你同步调用它,你通常仍会消耗相同数量的资源(事实上,你使用的更多,因为它有开销因安排某事而招致).
所以我想让我们尝试一下,然后我创建了使用WebClient's DownloadStringTaskAsync和DownloadString(同步)方法的演示应用程序.
我的演示应用程序有两种方法
DownloadHtmlNotAsyncInAsyncWay
这提供了围绕同步方法的异步方法包装器,DownloadString它不应该扩展良好.
DownloadHTMLCSAsync
这会调用异步方法DownloadStringTaskAsync.
我从两种方法中创建了100个任务并比较了消耗的时间,发现选项1比第二个消耗的时间少.为什么?
这是我的代码.
using System;
using System.Diagnostics;
using System.Net;
using System.Threading.Tasks;
public class Program
{
public static void Main()
{
const int repeattime = 100;
var s = new Sample();
var sw = new Stopwatch();
var tasks = new Task<string>[repeattime];
sw.Start();
for (var i = 0; i < repeattime; i++)
{
tasks[i] = s.DownloadHtmlNotAsyncInAsyncWay();
}
Task.WhenAll(tasks);
Console.WriteLine("==========Time elapsed(non natural async): " + sw.Elapsed …Run Code Online (Sandbox Code Playgroud) c# ×8
linq ×2
sql-server ×2
string ×2
.net ×1
async-await ×1
c ×1
char ×1
identity ×1
linq-to-sql ×1
return-value ×1
t-sql ×1
textbox ×1