我有一个事件,在数据网格视图中单击一个单元格,以在消息框中的单击单元格中显示数据.我将它设置为仅适用于某个列的位置,并且仅当单元格中有数据时才设置
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex.Equals(3))
if (dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null)
MessageBox.Show(dataGridView1.CurrentCell.Value.ToString());
}
Run Code Online (Sandbox Code Playgroud)
但是,每当我单击任何列标题时,都会显示一个空白消息框.我无法弄清楚为什么,任何提示?
我今天被问到了这个问题,我知道答案很简单,但他让我一直到最后.
编写程序以删除存储在ArrayList包含中的偶数1 - 100.
在这里,你这就是我实现它的方式.
ArrayList source = new ArrayList(100);
for (int i = 1; i < 100; i++)
{
source.Add(i);
}
for (int i = 0; i < source.Count; i++)
{
if (Convert.ToInt32(source[i]) % 2 ==0)
{
source.RemoveAt(i);
}
}
//source contains only Odd elements
Run Code Online (Sandbox Code Playgroud)
他问我计算复杂性是什么给他一个等式.我刚刚说过,这是线性与N(输入)成正比.
他说:嗯...这意味着我需要等待更长时间才能获得结果,当输入大小增加时,我是对的吗? Yes sirr you are
为我调整,Log(N)尽可能多地尝试.我在这部分失败了.
注意:他不想要Linq,没有额外的花里胡哨.只是简单的循环或其他逻辑来做到这一点
我需要在 C# 中从物理集合(无数据绑定)中填充 .net DataGridView。也就是说,我应该使用 foreach 循环并遍历集合,同时为每个对象创建一行并为每个属性创建一个单元格。
我已经在设计模式下创建了列。现在我需要动态创建行。
怎么做?
我有一个特定的文本文件:
197 17.16391215
198 17.33448519
199 17.52637986
200 17.71827453
201 17.9101692
202 18.10206387
203 18.29395854
204 18.48585321
205 18.67774788
206 18.86964255
207 19.06153722
Run Code Online (Sandbox Code Playgroud)
等等.需要说明的是:第一列(197,198,..)表示帧号,第二列(17.xxx,...)表示链接到帧号的位置,反之亦然.
现在我想在不同的数组中分隔每一行.同
string[] delimiters = new string[] {" ", "\r\n" };
string line = reader.ReadToEnd();
string[] test = line.Split(delimiters, StringSplitOptions.None);
Run Code Online (Sandbox Code Playgroud)
我有一个包含Textfile中所有条目的数组.但我希望所有framenumbers(第一列)在一个Array中,而在另一个第二个Array中所有位置.
我需要做的工作如下:我将得到一个位置编号(例如18.10)然后我必须在第二列的.txt文件中搜索最接近的匹配编号并返回链接的框架编号(在这种情况下为202) .我的想法是生成两个匹配的数组,在一个中搜索位置,从另一个中返回framenumber.当我在互联网上搜索了半天时,发现很多东西,比如所有的.select东西,但没有任何东西直接匹配我的问题; 但也许我此刻是愚蠢的.
所以感谢任何帮助.希望你能理解我的英语:P
假设我有这3个班级.
abstract class MyBase
{
//some base code here
}
class Foo : MyBase, IDisposable
{
//got at least a field I should dispose
}
class Bar : MyBase, IDisposable
{
//got at least a field I should dispose
}
Run Code Online (Sandbox Code Playgroud)
我有几个这样的课程.我上课了List<base>.我怎样才能正确处理所有这些类而无需测试/强制转换以获得正确的类型然后拥有Dispose?
我想知道什么是最佳实践,或者至少是什么是超载的标准.我正在使用c#3.5,所以我没有可选参数.假设我有以下方法:
Foo(string param1, string param2)
{
SqlConnection connection = SM.Program.GetConnection();
SqlCommand command = connection.CreateCommand();
command.CommandText = "UPDATE Table" +
"SET Pla = @pla " +
"WHERE Foo = @foo";
try
{
command.Parameters.AddWithValue("@pla", param1);
command.Parameters.AddWithValue("@foo", param2);
connection.Open();
command.ExecuteNonQuery();
}
finally
{
connection.Dispose();
command.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
而且我需要一个带有另一个参数的重载,比如一个sqltransaction
Foo(string param1, string param2, SqlTransaction trans)
Run Code Online (Sandbox Code Playgroud)
第二种方法基本上是相同的,但它会在事务中执行操作
现在我想知道我该怎么办?只有一种接受null argurment作为事务的方法,在这种情况下,不使用任何或2种方法,但除了事务之外,还可以使用mutch复制/粘贴代码?
什么被认为是这种事情的最佳做法?
编辑:我认为一般的想法似乎在超载之间进行链接.但我仍然想知道在那种情况下不接受null参数的方法是一种坏事吗?
我有一个包含登录名,数据库和密码的字符串.
string str = "user Id=abc, database=DDD, Password=mypasswd"
Run Code Online (Sandbox Code Playgroud)
我希望能够用不同的值替换数据库值"DDD".
我尝试使用string.Replace,但我不知道现有的数据库是什么.
有谁知道一个简单的解决方案?
我正在尝试制作一个程序,用于根据用户给出的数字计算某些特定数据.在这个例子中,我的程序计算范围(10,103)中可被2整除的数字量,以及范围(15,50)中的数字量,在用户给出的数字内可被3整除.在这个阶段,我的程序给出结果,当给出10个数字时(正如我在循环中指定的那样).当用户输入空行时,无论是否输入5或100个数字,如何让我的程序停止读取数字并给出结果?
这是我的代码,因为它现在寻找:
using System;
namespace Program1
{
class MainClass
{
public static void Main (string[] args)
{
int input10_103_div_2 = 0;
int input15_50_div_3 = 0;
for (int i = 0; i < 10; i++)
{
string input = Console.ReadLine ();
double xinput = double.Parse (input);
if (xinput > 10 && xinput <= 103 && (xinput % 2) == 0)
{
input10_103_div_2++;
}
if (xinput > 15 && xinput < 50 && (xinput % 3) == 0)
{
input15_50_div_3++;
}
} …Run Code Online (Sandbox Code Playgroud) 我有以下linq声明:
_champs.Where(a => a.NoPage == noPage + 1).Any()
Run Code Online (Sandbox Code Playgroud)
和
_champs.Any(a => a.NoPage == noPage + 1)
Run Code Online (Sandbox Code Playgroud)
在if条件下.
第一个看起来更容易为我阅读,看起来比第二个更好的逻辑,但两者都工作得很好.
是否有任何理由使用#1而不是#2或反之亦然?
编辑:我会坚持第二个,因为它似乎比第一个好一点.它也很容易阅读,听起来更自然......实际上我在代码中经常找到第二个(快速查找之后)
我试图使用从元素内的控制器填充的内容,以便我可以使用内容来构建视图.
到目前为止,我有以下元素(.ctp文件)
<?php $categories = $this->requestAction('categories/menu'); ?>
<ul class="hidden">
<?php foreach ($categories as $categorie): ?>
<li><?= $this->Html->link($categorie->name, '#'); ?></li>
<?php endforeach; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)
用这个控制器
class CategoriesController extends AppController
{
public function index()
{
$categories = $this->Categories->find('all');
$this->set(compact('categories'));
}
public function menu()
{
$categories = $this->paginate();
$this->set('categories', $categories);
}
}
Run Code Online (Sandbox Code Playgroud)
使用此处的代码时,我在日志中出现错误,页面上没有显示任何内容Error: [Cake\View\Exception\MissingTemplateException] Template file "Categories\menu.ctp" is missing.
.
如果我为此更改此ligne $this->set('categories', $categories);,return $categories;我的页面上会显示以下错误Error: Controller action can only return an instance of Response.
我最初尝试了本教程中的代码(抱歉滚动只是转到缓存元素 …
c# ×9
.net ×2
datagridview ×2
algorithm ×1
cakephp-3.0 ×1
cell ×1
file-io ×1
idisposable ×1
linq ×1
parsing ×1
search ×1
string ×1