我有一个程序从dataGridView中的选定行获取值并将其传递给函数.但是,gridView可能为空或无法选择行.我处理了空网格,但我想知道是否有办法,如果我可以判断是否选择了任何行.
我试过这个:
if (Convert.ToInt32(dataGridView1.Rows.Count) > 0)
{
//It is not empty
}
int c = dataGridView1.SelectedRows.Count(); //this line gives me an error
if (c>0)
{
//there is a row selected
}
Run Code Online (Sandbox Code Playgroud)
你知道我怎么解决这个问题?
我有以下界面和具体类.
我收到的错误是:
'DAL.Model.Audit.Categories'无法实现'DAL.Interfaces.IAudit.Categories',因为它没有匹配的返回类型'System.Collections.Generic.IEnumerable'.
有谁能请解释我在这里做错了什么?
public interface IAudit
{
IEnumerable<ICategory> Categories { get; set; }
IEnumerable<IAuditAnswer> Answers { get; set; }
}
public class Audit : IAudit
{
public List<ICategory> Categories { get; set; }
public List<IAuditAnswer> Answers { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我有一个小的powershell脚本,该脚本读取UTF8编码的文档,在其中进行一些替换,然后将其保存起来,如下所示:
(Get-Content $path) -Replace "myregex","replacement" | Set-Content $path2 -Encoding utf8
Run Code Online (Sandbox Code Playgroud)
这将创建一个具有正确编码和正确内容的新文件,但末尾还有其他换行符。根据这个答案和许多其他答案,我被告知要:
-NoNewLine到Set-Content[System.IO.File]::WriteAllText($path2,$content,[System.Text.Encoding]::UTF8)两种解决方案都删除尾随的新行... 以及文件中的所有其他新行。
有两种方法都可以:
我编写了一个函数,从列表中获取给定数量的随机记录.目前我可以这样做:
IEnumerable<City> cities = db.Cites.GetRandom(5);
Run Code Online (Sandbox Code Playgroud)
(其中db是我的DataContext连接到SQL Server数据库)
目前,我在每个需要随机记录的实体中都有这样的函数:
public partial class City
{
public static IEnumerable<City> GetRandom(int count)
{
Random random = new Random();
IEnumerable<City> cities = DB.Context.Cities.OrderBy( c => random.Next() ).Take(count);
return cities;
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我希望它是通用的,所以它可以适用于任何表,甚至任何项目列表.我尝试了一种扩展方法,如:
public static IEnumerable<T> GetRandom<T>( this Table<T> table, int count)
{
Random random = new Random();
IEnumerable<T> records = table.OrderBy(r => random.Next()).Take(count);
return records;
}
Run Code Online (Sandbox Code Playgroud)
但我得到:
Error 1 The type 'T' must be a reference type in order to use it as parameter 'TEntity' …
我创建了一个webView:
videoView.delegate = self;
videoView.userInteractionEnabled = true;
[videoView loadRequest:[[NSURLRequest alloc]initWithURL:[[NSURL alloc] initWithString:@"website"]]];
Run Code Online (Sandbox Code Playgroud)
我有html/javascript来处理视频的加载以及自动播放和下一个视频.这一切都有效,但我的问题是IOS自动加载像quicktime这样的播放器,这也是一件好事,但我不知道如何控制它,也不知道如何让视频播放一旦发生.我希望播放器中显示的按钮能够自动播放.我希望无论何时加载新视频都会发生这种情况.
JS代码就是这样的.我列出了一个列表,这是我的播放列表.我没有从youTube加载播放列表我只是制作自己的列表,当调用视频结束时,我按ID加载新视频.我还自动播放了视频,这就是IOS在视频加载时随时提供的按钮.另外,我使用iframe来完成所有这些,使用youTube api,这就是我对js方面的控制.
问题:有没有办法通过代码控制游戏?如果是这样的话,当播放器已经加载并且我加载另一个视频时,我如何才能将其设置为自动播放?
我找到了答案:
如果你把webView.mediaPlaybackRequiresUserAction=FALSE;在webViewDidFinishLoad那么它会自动播放,仍然让你使用其他按钮也是如此.这就像一个魅力,建议使用它.
我正在制作农场/塔防游戏,我在编程时非常新.我似乎在XNA中使用Lists <>或数组时遇到了一个主要问题.我无法让它从列表中返回我想要的索引.
主要问题是我的种植引擎.我已经成功实施了种植系统,可以生成具有不同属性的植物(精灵对象)列表并将它们放在地图上.现在,我需要一种方法来访问工厂列表中的特定工厂,基于鼠标点击该工厂.我觉得我非常接近,但最终我得到了一个无法解决的ArgumentOutOfRangeException.以下是代码的演练:
初始化
public void Addplants()
{
switch (Mode)
{
case "Wotalemon":
NewPlant = new Plant(Texture, msRect);
NewPlant.AddAnimation("seed", 0, 16, 64, 64, 1, 0.1f);
NewPlant.AddAnimation("sprout", 64, 16, 64, 64, 1, 0.1f);
NewPlant.AddAnimation("wota", 128, 16, 64, 64, 1, 1.0f);
NewPlant.CurrentAnimation = "seed";
NewPlant.DrawOffset = new Vector2(32, 48);
NewPlant.Position = Position;
NewPlant.Type = "wotalemon";
NewPlant.Birthday = Days;
NewPlant.IsSelected = false;
plants.Add(NewPlant);
thisPlant = NewPlant;
//various plants after this
Run Code Online (Sandbox Code Playgroud)
更新/绘图
我使用一些简单的foreach循环来更新和绘制植物,这里没有问题.
GetInfo(此方法使用spriteobject的hitbox属性和mouseRectangle)
public void GetInfo(Rectangle ms)
{
msRect = ms;
for (int …Run Code Online (Sandbox Code Playgroud) 我在C#3.5中有一个字符串数组:
string [] times = new[] {“08:00 am” , “10:00 am”, “120”} ;
Run Code Online (Sandbox Code Playgroud)
我想创建索引的时间:StartTime,EndTime,ElapsedTime所以,当我的代码:
StartTime= “09:00 am” ;
EndTime= “11:00 am” ;
Run Code Online (Sandbox Code Playgroud)
然后times[0]设置为“09:00 am”等
我可以创建3种方法:
private void StartTime(string time)
{ times[0] = time; }
private void EndTime(string time)
{ times[1] = time; }
private void ElapsedTime(string time)
{ times[2] = time; }
Run Code Online (Sandbox Code Playgroud)
和代码
StartTime("09:00");
Run Code Online (Sandbox Code Playgroud)
但有更简单的方法吗?
我遇到了Except()方法的麻烦.它不返回差异,而是返回原始集合.
我已经尝试在Account类中实现IEquatable和IEqualityComparer.我也尝试为Account创建一个单独的IEqualityComparer类.
当从main调用Except()方法时,它似乎不会调用我的自定义Equals()方法,但是当我尝试Count()时,它确实调用了自定义的GetHashCode()方法!
我确定我在某个地方犯了一个小错误,我希望一双新眼睛可以帮助我.
主要:
IEnumerable<Account> everyPartnerID =
from partner in dataContext.Partners
select new Account { IDPartner = partner.ID, Name = partner.Name };
IEnumerable<Account> hasAccountPartnerID =
from partner in dataContext.Partners
from account in dataContext.Accounts
where
!partner.ID.Equals(Guid.Empty) &&
account.IDPartner.Equals(partner.ID) &&
account.Username.Equals("Special")
select new Account { IDPartner = partner.ID, Name = partner.Name };
IEnumerable<Account> noAccountPartnerID =
everyPartnerID.Except(
hasAccountPartnerID,
new LambdaComparer<Account>((x, y) => x.IDPartner.Equals(y.IDPartner)));
Run Code Online (Sandbox Code Playgroud)
帐户:
public class Account : IEquatable<Account>
{
public Guid IDPartner{ get; set; }
public string Name{ get; set; } …Run Code Online (Sandbox Code Playgroud) 我想用两个条件打印两个arraylists的元素.但是在尝试实现它时我得到了Concurrent Modification异常.
我做错了什么?
public void Insert_Answers(Enumeration<String> ques, Enumeration<String> ans){
try {
while(ans.hasMoreElements()){
String answer = ans.nextElement();
System.out.println(answer);
while(ques.hasMoreElements()){
String question = ques.nextElement();
System.out.println(question);
}
}
}
catch (Exception ex) {
Logger.getLogger(DbInsert.class.getName()).log(Level.SEVERE, null, ex);
}
}
Run Code Online (Sandbox Code Playgroud)
这是包含main方法的Test.java类
public class Test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
DbInsert dbIns = new DbInsert();
ArrayList<String> arr1 = new ArrayList<String>();
arr1.add("a");
arr1.add("b");
arr1.add("c");
arr1.add("d");
Enumeration earr1 = Collections.enumeration(arr1);
ArrayList<String> arr2 = new ArrayList<String>();
arr2.add("e");
arr1.add("f"); …Run Code Online (Sandbox Code Playgroud) c# ×6
linq ×2
list ×2
.net ×1
arraylist ×1
datagridview ×1
generics ×1
ienumerable ×1
iequatable ×1
iframe ×1
interface ×1
ios ×1
java ×1
linq-to-sql ×1
powershell ×1
uiwebview ×1
utf-8 ×1
webview ×1
winforms ×1
xna ×1
youtube ×1