我想获得的关键SelectedItem的ComboBox,但不弄清楚如何让我做的是代码,
void CboBoxSortingDatagridview(ComboBox sender)
{
foreach (var v in DictionaryCellValueNeeded)
{
if (!DictionaryGeneralUsers.ContainsKey(v.Key) && v.Value.RoleId == Convert.ToInt32(((ComboBox)sender).SelectedItem)) // here getting value {1,Admin} i want key value which is 1 but how?
{
DictionaryGeneralUsers.Add(v.Key, (GeneralUser)v.Value);
}
}
dataGridViewMain.DataSource = DictionaryGeneralUsers.Values;
}
Run Code Online (Sandbox Code Playgroud)
我用这种方式绑定了组合框,
cboRolesList.DataSource = new BindingSource(dictionaryRole, null);
cboRolesList.DisplayMember = "Value";
cboRolesList.ValueMember = "Key";
Run Code Online (Sandbox Code Playgroud) 我们注意到一些我们无法解释的奇怪事 在课堂上我们有这两个功能:
Public Overloads Shared Function ToList(ByVal input As Object, _
Optional ByVal StringSeparator As String = ";", _
Optional ByVal CharacterCasing As String = "", _
Optional ByVal StartRow As Integer = 0, _
Optional ByVal EndRow As Integer = -1) As String
...
End Sub
Public Overloads Shared Function ToList(ByVal Input As Object, _
Optional ByVal SplitStringSeparator As String = ",", _
Optional ByVal JoinStringSeparator As String = ",", _
Optional ByVal PreFixStr As String = "", _ …Run Code Online (Sandbox Code Playgroud) 在C++中我知道当一个打算从基类继承时,通常应该使用虚拟析构函数.但是,使用C#我不知道该怎么做.请考虑以下代码:
public abstract class Character
{
private string characterName;
public int health;
Character()
{
}
~Character(){
}
public virtual void SetCharacterName( string tempName )
{
characterName = tempName;
}
public virtual string GetCharacterName( )
{
return characterName;
}
}
Run Code Online (Sandbox Code Playgroud)
(注意:我听说Unity的Unity3Ds实现与标准略有不同.也许忽略一些小的格式错误,代码似乎功能......)
我的第一直觉是将~Character()析构函数设为虚拟,将其定义为:
virtual ~Character(){
}
Run Code Online (Sandbox Code Playgroud)
但这样做会导致IDE返回错误.
在C#中,对于希望继承的抽象类,使用虚拟析构函数是必要的还是被认为是标准的?还是有其他方法用C#制作虚拟析构函数?
我创建了一个类的3个对象,我想在控制台上显示我创建了多少个对象(使用静态类变量) - 我该怎么做?
我放入public static int count = 0;了我创建的类,但count++;根据我创建的类的对象数量,我无法使用increment().我在main方法中创建了3个对象,并为变量赋予了它们的值.
这是我在程序中创建的类:
public class Student
{
public static int count = 0;
// count++;
private string firstName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
private string lastName;
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
private string birthDate;
public string BirthDate
{
get { return birthDate; }
set { birthDate = …Run Code Online (Sandbox Code Playgroud) 一位同事给了我一些我必须在.NET应用程序中使用的C#类.
有一个我从未见过的拼写错误,我在互联网上找不到任何解释......
这是代码:
public void GoTo<TView>() where TView : Form, new()
{
var view = Activator.CreateInstance<TView>();
//si on vient de creer une startup view alors on affiche l'ancienne
//la reference a la nouvelle sera detruite en sortant de la fonction GoTo
if (view is StartupForm)
{
ShowView(_StartupForm);
}
else ShowView(view);
}
Run Code Online (Sandbox Code Playgroud)
new()在方法声明的最后是什么关键字?
我上课了Person:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public void Deconstruct(out int id) { id = Id; }
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下代码解构它时:
var (id) = new Person();
Run Code Online (Sandbox Code Playgroud)
编译器说:
无法推断出隐式类型的解构变量'id'的类型.
当有多个参数时,编译器不会说出来.像这样:
public void Deconstruct(out int id, out string name) { id = Id; name = Name; }
var (id, name) = new Person();
Run Code Online (Sandbox Code Playgroud) 有一个非常简单的问题这是我的代码:
$imax = 3;
$licenses = array('pub1','pub2','pub3');
for ($i=0; $i<=$imax; $i++) {
$pub = $licenses[$i];
switch ($pub){
case 'pub1': $pubtitle = "Pub title 1";
case 'pub2': $pubtitle = "Pub title 2";
case 'pub3': $pubtitle = "Pub title 3";
}
echo $pubtitle;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
Pub title 3
Pub title 3
Pub title 3
Run Code Online (Sandbox Code Playgroud)
我试图放入$pubtitle一个数组,但它也不起作用:(
我试图在C#WinForms应用程序的网站上获得少量文本框的值.它是输入类型文本,设置为只读,但当我尝试在我的应用程序中使用时读取它
string price = webBrowser1.Document.GetElementById("price").GetAttribute("value");
Run Code Online (Sandbox Code Playgroud)
它返回一个空字符串.当我尝试使用设置其他(非只读)输入值时.SetAttribute("value", "testValue"),它工作得很好.
有人可以帮我这个吗?
我有一个FormBorderStyle设置为的程序None。我一直在网上寻找可以找到用于调整表单大小的有效代码,但是它仅在表单有空白空间且没有控件时才起作用。我的整个表单虽然充满了控件,但每个边缘都包含控件,因此我无法在边缘中腾出空间。有什么方法可以使用Windows API或其他方法来扩展调整大小范围,或者在何时使用控件来触发调整大小事件MouseDown?
是否有可能有一个数组属性返回在同一索引处的其他2个数组的计算?
public ushort[] LowLimit{ get; set; }
public ushort[] Range{ get; set; }
public ushort[] HiLimit {
get {
return LowLimit + Range;
}
}
Run Code Online (Sandbox Code Playgroud)
所以,如果我打电话,HiLimit[0]它会回来LowLimit[0] + Range[0].这不起作用但必须有办法.
c# ×8
syntax ×2
winforms ×2
arrays ×1
c#-7.0 ×1
combobox ×1
for-loop ×1
html ×1
inheritance ×1
keyvaluepair ×1
keyword ×1
new-operator ×1
php ×1
resize ×1
vb.net ×1