我有stringBuilder和string类,存储路径:
StringBuilder name = new StringBuilder();
name.Append(@"NETWORK\MyComputer");
String serverName = name.ToString(); //this converts the \ to a \\
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多东西,但它总是导致字符串有\
使用serverName.Replace("\\", @"\");不起作用,它留下它作为\
servername.Replace("\\", "\"");"在字符串中 添加一个仍然不正确的字符串.
请协助.
请耐心等待我,因为我正在学习C#.只是搞乱C#我决定提出一个库存系统来测试,但我的脚本中有一个问题:
using System;
using System.Collections.Generic;
public class Item
{
public String name;
public int pesos;
public int getPesos()
{
return pesos;
}
public String getName()
{
return name;
}
}
public class statuseffect
{
statuseffect(string Effect,int Amount,int Duration)
{
string effect = Effect;
int amount = Amount;
int duration = Duration;
}
}
public class Potion : Item
{
public int hpeffect;
public int mpeffect;
List<statuseffect> effects = new List<statuseffect>();
public Potion(int hp,int mp)
{
hpeffect = hp;
mpeffect = …Run Code Online (Sandbox Code Playgroud) 我理解这个话题得到了很多回答.我的问题是针对它的说法或问题.
所以我说得对,用class关键字编写的代码将在托管堆上并且是一个引用类型,用struct编写的代码将在堆栈上并且是一个值类型?
private static DateTime FromMS(long microSec)
{
long milliSec = (long)(microSec / 1000);
DateTime startTime = new DateTime(1970, 1, 1);
TimeSpan time = TimeSpan.FromMilliseconds(milliSec);
DateTime v = new DateTime(time.Ticks);
DateTime result = new DateTime(startTime.Year + v.Year, startTime.Month + v.Month, startTime.Day + v.Day, startTime.Hour + v.Hour, startTime.Minute + v.Minute, startTime.Millisecond + v.Millisecond);
return result;
}
Run Code Online (Sandbox Code Playgroud)
这个结果是错误的……为什么???
我很抱歉这个看起来很愚蠢的问题,但我真的很困惑
这句话 :
String myline = "<form name='oldvalue' action='old_value' method='get'>"
Run Code Online (Sandbox Code Playgroud)
预期结果 :
<form name='oldvalue' action='new_value' method='get'>
Run Code Online (Sandbox Code Playgroud)
我想在操作后的引号之间替换文本的值.
我不想使用myLine.Replace,因为句子中action属性的值是随机的,我不关心它.它的价值我希望被它取代new_value
我怎样才能做到这一点!谢谢.
我尝试在MSDN,SO和Web上搜索,但找不到答案.
说我有一个我喜欢的收藏品FirstOrDefault().我们说它找到了这个项目.它会停止并返回该项目还是继续搜索并阻碍性能?
我需要调用一个方法,传递一个 int。使用以下代码我可以获取该方法但不传递参数。如何修复它?
dynamic obj;
obj = Activator.CreateInstance(Type.GetType(String.Format("{0}.{1}", namespaceName, className)));
var method = this.obj.GetType().GetMethod(this.methodName, new Type[] { typeof(int) });
bool isValidated = method.Invoke(this.obj, new object[1]);
public void myMethod(int id)
{
}
Run Code Online (Sandbox Code Playgroud) 我有一个列表,listIn用n多个元素调用.我有另一个列表,ind用melements(m<n)调用它.ind是我想要保留的指数listIn,并删除其他指数.
我可以通过运行循环来做到这一点,但我很好奇是有一种聪明的方法来做到这一点.
例如.
listIn = [0,1,2,3,4,5,6,7,8,9,10]; // 11 elements
ind = [4,7,8] // 3 indices
Result = drop all elements excepts ones at 4,7,8.
Run Code Online (Sandbox Code Playgroud) 我正在使用"#"自定义格式将我的整数值转换为字符串值
string str = string.Format("{0:###,###}", 10000);
Run Code Online (Sandbox Code Playgroud)
结果是"10,000".
但是当值为0时,str为空.
string str = string.Format("{0:###,###}", 0);
Run Code Online (Sandbox Code Playgroud)
我知道这已经在MSDN中解释过了,但我想在值为零时显示0.怎么做?
string file = "";
int size = -1;
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
openFileDialog1.Filter = "Excel |*.xlsx"; //"Excel Files|(*.xlsx, *.xls)|*.xlsx;*.xls";
openFileDialog1.FilterIndex = 1;
if(result == DialogResult.OK) // Test result.
{
file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch(System.IO.IOException)
{
}
}
tempLBL.Text = file;
Run Code Online (Sandbox Code Playgroud)
我还测试了上面提到的过滤器。当我浏览...和显示所有文件时,它没有显示任何过滤器。我需要的是,当单击“浏览”按钮时,只有XLSX或XLS文件显示给用户。
提前致谢
c# ×10
.net ×2
vb.net ×2
class ×1
constructor ×1
excel ×1
heap ×1
ienumerable ×1
linq ×1
reflection ×1
stack ×1
string ×1
struct ×1