这是一个非常基本的问题,但我不确定为什么它不起作用.我有代码,其中'和'可以用'And','和'等方式编写,我想用','替换它'
我试过这个:
and.Replace("and".ToUpper(),",");
Run Code Online (Sandbox Code Playgroud)
但这不起作用,任何其他方式来做到这一点或使其工作?
最终结果是我想要使用.Where(t => someIntList.Contains(t.ID)).ToList().我正在努力创造someIntList.
到目前为止我所拥有的:List<Person> people = people.Where(p => p.isActive).ToList().我该如何归还一List<int>处p.ID房产?
或者是否有另一种方法可以做包含(没有编写Comparer类,因为我已经有一个用于其他目的.
嘿,我想要有类似的东西
int a=0;
a=5(be unchangeable);
a=3;
Console.WriteLine(a);//which will print 5 and not 3
Run Code Online (Sandbox Code Playgroud)
所以基本上把变量声明为一个数字,并让它是最终的和不可更改的,我试着四处寻找,但我只发现了一些工作为int的东西,而不是声明它的新值.
我试图Address从以下XML文本中获取元素的值,但除非xmlns="http://www.foo.com"从Root元素中删除,否则它找不到它.但是,即使使用它,XML也是有效的.这有什么问题?
由于我从Web服务获取XML文本,因此我无法控制它,但xmlns如果我必须作为最后的手段,我可以删除该部分.
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.foo.com">
<Address>Main St SW</Address>
</Root>
Run Code Online (Sandbox Code Playgroud)
var doc = XDocument.Parse(xmlTextAbove);
var address = doc.Descendants().Where(o => o.Name == "Address").FirstOrDefault();
Console.WriteLine(address.Value); // <-- error, address is null.
Run Code Online (Sandbox Code Playgroud) 我正在尝试用 c# 制作一个加密系统。这是加密的代码。
public static void EncryptFile(string inFile, string outFile, string @inkey)
{
try
{
UnicodeEncoding ue = new UnicodeEncoding();
byte[] key = ue.GetBytes(inkey);
FileStream fsEncrypt = new FileStream(outFile, FileMode.Create);
RijndaelManaged rmCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsEncrypt, rmCrypto.CreateEncryptor(key, key), CryptoStreamMode.Write);
FileStream fsIn = new FileStream(inFile, FileMode.Open);
int data;
while((data=fsIn.ReadByte()) != 1){
cs.WriteByte((byte)data);
}
fsIn.Close(); cs.Close(); fsEncrypt.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Fail to encrypt", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这段代码每次运行时都会抛出异常,说
指定的初始化向量 (IV) 与此算法的块大小不匹配
我读过其他关于这个的讨论,说字节数有问题(我传递给这个函数的密钥长度是 255)。但是我尝试将密钥设置为仅 16 个字节,但仍然无法正常工作。
经过一些故障排除后,我发现这部分: …
对不起,我是C#和WPF的新手.
namespace MyProgram
{
/// <summary>
/// Description of TSearchFiles.
/// </summary>
public class TSearchFiles
{
private TBoolWrapper canceled;
public TSearchFiles(TBoolWrapper bw)
{
canceled = bw;
}
public List<TPhotoRecord> GetFilesRecursive(string b)
{
List<TPhotoRecord> result = new List<TPhotoRecord>();
return result;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
Error 1 Inconsistent accessibility: return type 'System.Collections.Generic.List<MyProgram.TPhotoRecord>' is less accessible than method 'MyProgram.TSearchFiles.GetFilesRecursive(string)'
Run Code Online (Sandbox Code Playgroud)
怎么解决?代码在Winforms中编译得很好
提前致谢.
示例如下所示:
interface IA
{
ICollection<IB> Bs {get;set;}
}
interface IB
{
}
public class BBase : IB
{
}
public class ABase : IA
{
public ICollection<BBase> Bs { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我想实现界面IA时BBase,正如我所做的那样ABase,发生了错误.是说我只能用IB而不是BBase实现IAin ABase?
我不想要任何排序或任何花哨的东西.我只想要左边有两列有名字,右边有数字.
像这样的东西:
string/int[,] myArray = new string/int[,]();
Run Code Online (Sandbox Code Playgroud)
每个字符串都有一个对应的int.但我不希望它用于排序或任何东西.我知道我可以使用字典和其他我知道如何使用的高级方法.我想简单一点,我希望看到它是最简单的形式,我如何制作一个像这样的2种类型的数组.我能想到的最简单的方法是只使用对象,然后再显式转换.有更简单的方法吗?
我正在尝试使用屏蔽文本框输入IP,并且数字当前正用逗号分隔.有没有办法用点字符替换逗号字符?
到目前为止,这是我屏蔽文本框的定义:
//
// txtIPAddressForSaving
//
this.txtIPAddressForSaving.Font = new System.Drawing.Font("Microsoft Sans Serif", 30F);
this.txtIPAddressForSaving.Location = new System.Drawing.Point(148, 115);
this.txtIPAddressForSaving.Mask = "009.009.009.009";
this.txtIPAddressForSaving.Name = "txtIPAddressForSaving";
this.txtIPAddressForSaving.PromptChar = '.';
this.txtIPAddressForSaving.Size = new System.Drawing.Size(463, 53);
this.txtIPAddressForSaving.TabIndex = 13;
this.txtIPAddressForSaving.TabStop = false;
Run Code Online (Sandbox Code Playgroud) 我想知道如何获得无边界的C#.NET控制台应用程序.我的应用程序工作正常,但我不希望我的应用程序看起来像一个普通的表单,最小化,最大化和关闭按钮和左上角的图标和文本.
所以,我想知道如何实现这一目标.
好吧,你可以看到标题.我正在尝试构建一个config.ini将自动定位并在exe路径中生成..但是.我无法处理它.每次我这样做,我都会把你的来源腐烂成一个菜鸟.
我想做什么?
我想要这个ini加载程序.它将修改我将设置的一些选项(自动生成路径集"我创建了一个表单来自动启动一些exes,每次运行此表单时,它都会将文本框重置为空字段.")(自动设置sql连接像sqlconnection = 1 - >当它加载时,sql连接将自动运行,最新的成功连接发生在程序sqlconnection = 0 - >加载时,它不会加载sql连接.谁运行程序应该这样做手动)
我正在做一个刽子手游戏,并且刚刚开始创建随机单词,这将产生用户必须猜测的新单词,但是有时随机代码将生成与之前使用的相同的单词.我的问题是......是否有一个符号或代码,如果随机数不等于......那么这个代码块.
这是我的代码......
private void button1_Click(object sender, EventArgs e)
{
Random rW = new Random();
foreach (TextBox textBox in addTextBox())
{
textBox.Visible = false;
}
RW = rW.Next(1, 4);
if (RW == 1) //Cat
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
}
else if (RW == 2) //Elephant
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = true;
textBox8.Visible = true;
}
else if (RW == …Run Code Online (Sandbox Code Playgroud) c# ×12
.net ×1
c#-4.0 ×1
cmd ×1
cryptography ×1
declaration ×1
exception ×1
interface ×1
linq ×1
linq-to-xml ×1
replace ×1
string ×1
variables ×1
winforms ×1
xml ×1