在运行时,我不知道变量v1是什么类型.出于这个原因,我写了很多if else陈述:
if (v1 is ShellProperty<int?>)
{
v2 = (v1 as ShellProperty<int?>).Value;
}
else if (v1 is ShellProperty<uint?>)
{
v2 = (v1 as ShellProperty<uint?>).Value;
}
else if (v1 is ShellProperty<string>)
{
v2 = (v1 as ShellProperty<string>).Value;
}
else if (v1 is ShellProperty<object>)
{
v2 = (v1 as ShellProperty<object>).Value;
}
Run Code Online (Sandbox Code Playgroud)
唯一的区别在于ShellProperty<AnyType>.
因此if else,我决定使用反射来在运行时获取属性类型,而不是使用大量语句编写它:
Type t1 = v1.GetType().GetProperty("Value").PropertyType;
dynamic v2 = (v1 as ShellProperty<t1>).Value;
Run Code Online (Sandbox Code Playgroud)
此代码获取PropertyType的v1,并将其分配给本地变量t1,但在那之后,我的编译器说:
t1是一个变量但是像一个类型一样使用
所以它不允许我在t1 …
一组2个元素的二进制运算数是2^(2*2)=16.

该集合上的关联二进制操作数仅为8.

一组3个元素的二进制运算数为3 ^(3*3)= 19683.
该集合上的关联二进制操作数仅为113.如何知道一组n个元素上有多少个关联二元运算?
另外,为了获得所有这113个操作并写入文件,有必要编写程序.
如果我将尝试获取所有19683操作,然后检查它的所有19683操作的关联属性"a*(b c)==(a b)*c",这将起作用但是这需要很长时间才能完成= 4个元素!
如何编写一个有效的算法来解决这个任务?
请帮我!
在 Windows 资源管理器中,当处于“大图标”或“超大图标”布局时,MP4 文件显示为缩略图。默认情况下,缩略图图像取自视频中间的某个帧。
如何用特定的封面图片替换这个自动生成的缩略图?
哪些 ffmpeg 命令会将封面图像添加到 MP4 视频文件?
为什么动态编程期间字典“不包含‘ElementAt’的定义”
Dictionary<string, dynamic> D1 = new Dictionary<string, dynamic>();
D1.Add("w1", 10);
D1.Add("w2", false);
Dictionary<string, dynamic> D2 = new Dictionary<string, dynamic>();
D2.Add("v1", 10);
D2.Add("v2", D1);
textBox1.Text += D2.ElementAt(1).Value.ElementAt(1).Value;
Run Code Online (Sandbox Code Playgroud)
我们应该在 textbox1“false”上得到结果
,但是我们会得到运行时错误:“不包含‘ElementAt’的定义”
如果您输入:
Dictionary<string, dynamic> var1 = D2.ElementAt(1).Value;
textBox1.Text += var1.ElementAt(1).Value;
Run Code Online (Sandbox Code Playgroud)
然后就可以正常工作了!
如何克隆或序列化 Windows 窗体控件?
当我尝试使用此代码“CloneControl(Control ct1)”克隆 Windows 窗体控件时,它允许我复制具有某些可序列化属性的控件,而不是所有属性。
public Form1()
{
InitializeComponent();
Columns = new DataGridViewTextBoxColumn[2];
for (int i = 0; i < 2; i++)
{
Columns[i] = new System.Windows.Forms.DataGridViewTextBoxColumn();
//
// Columns[i]
//
Columns[i].HeaderText = "j" + (i + 1);
Columns[i].Name = "Column" + (i + 1);
Columns[i].Width = 50;
}
dataGridView1 = new System.Windows.Forms.DataGridView();
dataGridView1.Name = "dataGridView1";
dataGridView1.Location = new System.Drawing.Point(100, 100);
dataGridView1.RowHeadersWidth = 50;
dataGridView1.RowTemplate.Height = 25;
dataGridView1.Size = new System.Drawing.Size(55 + 50 * 2, 25 + dataGridView1.RowTemplate.Height …Run Code Online (Sandbox Code Playgroud) 我做了一些C#程序,它获取了最新创建的文件.
例如它是一个D:\Directory1\file1.txt 文件
当它获取文件时,其文件的地址存储在某个变量中,如此字符串:
"D:\\Directory1\\file1.txt"
当您在调试中观察时,您可以看到此值.
FileInfo f1; // this is a latest created file "D:\Directory1\file1.txt"
string s1 = f1.FullName; // string value will be "D:\\Directory1\\file1.txt"
string s2 = SomeFunction(s1); // in order to get @"D:\Directory1\file1.txt" value
Run Code Online (Sandbox Code Playgroud)
如果将其值分配给不同的变量s2,那么您将再次获得相同的字符串值!
那么如何将此值赋给不同的变量以获得@"D:\ Directory1\file1.txt"值.
我应该使用StringBuilder类吗?
我应该使用String.Format吗?
还是非常感谢!
假设我有两个KeyValuePair变量.
KeyValuePair<string, double> kv1 = new KeyValuePair<string, double>("a", 5);
KeyValuePair<string, double> kv2 = new KeyValuePair<string, double>("b", 7);
Run Code Online (Sandbox Code Playgroud)
"KeyValuePair"结构中没有+ operation的定义.
所以我想使用运算符重载!
我的目标是获得第三个KeyValuePair类型变量,如:
KeyValuePair<string, double> kv1 = new KeyValuePair<string, double>(kv1.Key + " + " + kv2.Key, kv1.Value + kv2.Value);
Run Code Online (Sandbox Code Playgroud)
结果将是:
KeyValuePair<string, double>("a + b", 12)
Run Code Online (Sandbox Code Playgroud)
但是告诉我如何使用"运营商"来做到这一点?
我试图这样做:
public partial class Form1 : Form
{
public Form1()
{
KeyValuePair<string, double> kv1 = new KeyValuePair<string, double>("a", 5);
KeyValuePair<string, double> kv2 = new KeyValuePair<string, double>("b", 7);
KeyValuePair<string, double> k = kv1 + kv2;
}
public …Run Code Online (Sandbox Code Playgroud)