我在从列表中检索信息时遇到了一些问题。
在这种情况下,我想从列表中获取名称,最终我希望它变成一个字符串。这就是我所拥有的:
public string ShowName(int patientcode)
{
List<ExtendPatientInfo> patientdata = dk.RetrieveList(patientcode);
string name = patientdata. <What here?>
return name;
}
Run Code Online (Sandbox Code Playgroud)
在 ExtendPatientInfo 类中,我有这个,我认为没问题:
private string name;
public ExtendPatientInfo(string name)
{
this.name = name;
}
public string Name
{
get
{
return name;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用一些东西。像包含、查找、查找索引和位置。但是这些都不适合我,因为我可能在某个地方搞砸了。有人可以帮助我吗?
我正在重构一个较旧的应用程序,它使用动态内联SQL,从大型Oracle数据库中提取数据.我创建了一个工作正常的存储过程(PL/SQL).因为它只有一行(datarow),所以我让它返回一个数据行.该类位于DAL中.
在我重构的过程中,我认为我会将数据库(在DAL中)与业务层隔离(使用linQ).我的第一个想法是创建一个包含返回的数据行的对象.
我的一位同事推荐匿名类型,我不熟悉.在我迄今为止所做的阅读中,它看起来很简单.如果我仍然需要使用匿名类型放置字段名和字段类型,我只是没有看到它的值.
我错过了什么吗?如果我返回数据集/数据表,那么使用匿名类型会有更多价值吗?
我在MVC应用程序中使用LINQ.我注意到我可以通过两种方式创建一种方法,两种方法都有效,但我不知道哪种方法最好.
直接:
public string GetStatus(int PersonId)
{
return db.PersonStatus
.Where(x => x.personid == PersonId)
.Select(x => x.Status)
.Single();
}
Run Code Online (Sandbox Code Playgroud)
在var中首先:
public string GetStatus(int PersonId)
{
string Item = db.PersonStatus
.Where(x => x.personid == PersonId)
.Select(x => x.Status)
.Single();
return Item;
}
Run Code Online (Sandbox Code Playgroud)
我更喜欢第一种直接方法,因为它似乎更有效.如果两者之间存在显着差异,请告诉我,如果是,那么什么?
我有如下通用方法,我想将T限制为仅像Guid这样的类型:
public static EntityFindApiResponse EntityFind<T>(
Credential cred, EntitiesApiClient entitiesApiClient, string clrType,
string propertyName, T searchKey)
where T: Guid
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
编译器告诉我
'System.Guid'不是有效的约束.用作约束的类型必须是接口,非密封类或类型参数.
那么,为什么这不起作用?
我需要一个辅助函数来将字符串转换"1=alice;2=bob;3=charlie"为a Dictionary<int, string>,将字符串转换"1=true;2=false;3=true"为a Dictionary<int, bool>等等.
为此,我编写了许多辅助函数,它们基本上是相互复制和粘贴的:
private static void load(Dictionary<int, string> dict, string s)
{
dict.Clear();
string[] items = s.Split(';');
foreach (string item in items)
{
if (item.Contains("="))
{
string[] kv = item.Split('=');
dict[int.Parse(kv[0])] = kv[1];
}
}
}
private static void load(Dictionary<int, bool> dict, string s)
{
dict.Clear();
string[] items = s.Split(';');
foreach (string item in items)
{
if (item.Contains("="))
{
string[] kv = item.Split('=');
dict[int.Parse(kv[0])] = bool.Parse(kv[1]);
}
}
}
private static …Run Code Online (Sandbox Code Playgroud) 我正在使用ReSharper,在生成switch语句时遇到两种情况:
public void DoWork(MyEnum value)
{
switch(value)
{
// ...
default:
throw new ArgumentOutOfRangeException("value");
}
}
public void DoWork()
{
var value = GetEnumValue();
switch(value)
{
// ...
default:
// Cannot resolve symbol 'value'
throw new ArgumentOutOfRangeException("value");
}
}
Run Code Online (Sandbox Code Playgroud)
似乎如果我将枚举值作为参数传递,ReSharper不会抱怨它生成的代码.它识别出value在异常消息中适当使用.
但是,如果我在方法中以某种其他方式获取值作为局部变量,ReSharper似乎会抱怨它生成的代码,声称"无法解析符号'值'".这是有道理的,因为它value是一个局部变量,因此捕获异常消息的消费者不知道究竟value是什么.
那么,为什么会这样呢?
我可以通过 C# 关闭谷歌浏览器,如下所示:
Process[] chromeInstances = Process.GetProcessesByName("chrome");
foreach (Process p in chromeInstances)
{
p.Kill();
}
Run Code Online (Sandbox Code Playgroud)
但我不知道有什么方法可以检查谷歌浏览器是否正在运行。
我想知道如何首先检查谷歌浏览器是否正在运行,从而通过 C# 关闭谷歌浏览器。
我有一个linq查询,我Dictionary<int, string>将从中返回.我有一个重载的缓存方法,我已经创建了将一个Dictionary<T,T>项目作为参数之一.我有这个类,采取一些其他的方法List<T>,并T[]没有问题.但是这一个方法,拒绝使用线程主题的错误消息进行编译.
这是我的缓存类代码:
public static bool AddItemToCache<T>(string key, Dictionary<T, T> cacheItem, DateTime dt)
{
if (!IsCached(key))
{
System.Web.HttpRuntime.Cache.Insert(key, cacheItem, null, dt, TimeSpan.Zero);
return IsCached(key);
}
return true;
}
public static bool AddItemToCache<T>(string key, Dictionary<T, T> cacheItem, TimeSpan ts)
{
if (!IsCached(key))
{
System.Web.HttpRuntime.Cache.Insert(key, cacheItem, null, Cache.NoAbsoluteExpiration, ts);
return IsCached(key);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是无法编译的linq查询:
private Dictionary<int, string> GetCriteriaOptions()
{
Dictionary<int, string> criteria = new Dictionary<int, string>();
string cacheItem = "NF_OutcomeCriteria";
if (DataCaching.IsCached(cacheItem)) …Run Code Online (Sandbox Code Playgroud) 最近我读了"度量和网格设计指南".它谈到了我应该在布局中使用的48dp节奏.
但是"心灵差距"一章让我感到困惑.它指出:
每个UI元素之间的间距为8dp.
但是在这张图中:

在同一页面的示例中,8dp和4dp都用作填充/边距.
那么我应该使用的实际价值是多少?
我定义了一个css文件my_style.css并在我的页面中使用它.
body {
background-color: linen;
}
.myClass1 a:link,
a:visited {
color: orange;
margin-left: 40px;
}
.myClass2 a:link,
a:visited {
color: green;
margin-left: 40px;
}Run Code Online (Sandbox Code Playgroud)
<html>
<head>
<link href="my_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a class="myClass1" href="http://www.youtube.com">Link1</a>
<a class="myClass2" href="http://www.youtube.com">Link2</a>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
为什么两个链接都是绿色?
c# ×8
linq ×3
dictionary ×2
android ×1
constraints ×1
css ×1
enums ×1
generics ×1
html ×1
list ×1
performance ×1
process ×1
resharper ×1
types ×1
ui-design ×1