I have a question on Union
and Concat
. I guess both are behaving same in case of List<T>
.
var a1 = (new[] { 1, 2 }).Union(new[] { 1, 2 }); // O/P : 1 2
var a2 = (new[] { 1, 2 }).Concat(new[] { 1, 2 }); // O/P : 1 2 1 2
var a3 = (new[] { "1", "2" }).Union(new[] { "1", "2" }); // O/P : "1" "2"
var a4 = (new[] { "1", "2" …
Run Code Online (Sandbox Code Playgroud) 如何查找是否List<string>
有重复值?
我试过下面的代码.有没有最好的方法来实现?
var lstNames = new List<string> { "A", "B", "A" };
if (lstNames.Distinct().Count() != lstNames.Count())
{
Console.WriteLine("List contains duplicate values.");
}
Run Code Online (Sandbox Code Playgroud) 我有一个像下面这样的XML文件:
<Employees>
<Employee Id="ABC001">
<Name>Prasad 1</Name>
<Mobile>9986730630</Mobile>
<Address Type="Perminant">
<City>City1</City>
<Country>India</Country>
</Address>
<Address Type="Temporary">
<City>City2</City>
<Country>India</Country>
</Address>
</Employee>
Run Code Online (Sandbox Code Playgroud)
现在我想要获取所有地址类型.
我尝试下面使用XPath,我得到例外.
var xPathString = @"//Employee/Address/@Type";
doc.XPathSelectElements(xPathString); // doc is XDocument.Load("xml file Path")
Run Code Online (Sandbox Code Playgroud)
例外:XPath表达式计算为意外类型System.Xml.Linq.XAttribute.
我的XPath有什么问题吗?
这可能是一个简单的问题,但我很难解决.
我Web.config
在我的Web应用程序下面的值.
<appSettings>
<add key ="FirstName" value ="Prasad"/>
<add key ="LastName" value ="Kanaparthi"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
我App.config
在我的类库(说LIB)以下的值.
<appSettings>
<add key ="FullName" value ="Prasad Kanaparthi"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
类库(Lib)是可插入组件,我在Web应用程序中添加了类库(Lib)引用.
我的类库(Lib)中有以下代码.当我GetAppSettings
在我的Web应用程序中创建实例时,我可以看到以下响应.
namespace Lib
{
public class GetAppSettings
{
public GetAppSettings()
{
var FirstName = ConfigurationManager.AppSettings["FirstName"]; // O/P : Prasad
var MiddleName = ConfigurationManager.AppSettings["LastName"]; // O/P : Kanaparthi
var FullName = ConfigurationManager.AppSettings["FullName"]; // O/P : null
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是我怎么能读FullName
从App.config
它类库(LIB).
注意:由于我的Lib是可插拔组件,所以消费者可以改变FullName
自己的.我无法合并值Web.confing
从App.config …
我有一个不好的要求; 无论如何,我必须在我的应用程序中实现它.
我Track
上课了
public class Track
{
public string Name { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一些测试数据
List<Track> Records = new List<Track>
{
new Track { City = "a", Name = "a", Country = "i" }, // Track 1
new Track { City = "b", Name = "b", Country = "i" }, // Track 2
new Track { City = "a", Name = null, Country …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串数组变量.
private string[] _documents;
Run Code Online (Sandbox Code Playgroud)
它的值是这样分配的.
string[] _documents = { "doc1", "doc2", "doc3" };
Run Code Online (Sandbox Code Playgroud)
并且有一种方法可以将字符串添加到该数组并返回它.
public string GetMail()
{
return originalMessage + " " + _documents[0];
}
Run Code Online (Sandbox Code Playgroud)
定义_documents[0]
仅返回数组的第一个元素.
如何返回数组中的所有元素?(有点像PHP中的implode函数)
我正在尝试使用下面的正则表达式将数字格式化为数量格式.
var input = "1234567.00"
var pattern = @"\d(?=(\d{3},?)+\.)";
var replacement = "$$$&,";
var output = Regex.Replace(input, pattern, replacement);
Run Code Online (Sandbox Code Playgroud)
这给了我$ 1,23 $ 4,567.00(额外$).
我想在下面
Input:1234567.00 or 1234,567.00 or 1234567 should return $1,234,567.00
Run Code Online (Sandbox Code Playgroud)
请建议正确的.
我已经Constants.js
定义了以下变量的文件。
var baseApiUrl = "/api";
var ConstantAPI = {
employee: baseApiUrl + "/employee",
}
Run Code Online (Sandbox Code Playgroud)
我正在使用ConstantAPI.employee
我Constants.ts
也有过 我怎样才能访问baseApiUrl
文件.ts
。
我正在尝试像下面这样
export class DataService {
constructor(@Inject(HttpClient) private http: HttpClient) {
}
getEmployess(): Observable<any> {
var url = ConstantAPI.employee; // Error: Cannot find name 'ConstantAPI'
return this.http.post(url, searchData, options)
}
}
Run Code Online (Sandbox Code Playgroud) 我有FaultType
enum
超过100名成员.
public enum FaultType
{
FaultType1,
FaultType2,
FaultType3,
FaultType4,
FaultType5,
}
Run Code Online (Sandbox Code Playgroud)
我有一个FaultTypeConstants
class
对应的FaultType
.
public class FaultTypeConstants
{
public const int FaultType1 = 600;
public const int FaultType2 = 100;
public const int FaultType3 = 453;
public const int FaultType4 = 200;
public const int FaultType5 = 300;
}
Run Code Online (Sandbox Code Playgroud)
我试过了..
public static List<FaultType> GetFaults(List<int> FaultConstants)
{
var faults = new List<FaultType>();
FaultConstants.ForEach(fc => {
switch (fc)
{
case FaultTypeConstants.FaultType1:
faults.Add(FaultType.FaultType1);
break;
case FaultTypeConstants.FaultType2:
faults.Add(FaultType.FaultType2); …
Run Code Online (Sandbox Code Playgroud) c# ×8
linq ×3
angular ×1
arrays ×1
asp.net ×1
c#-4.0 ×1
javascript ×1
linq-to-xml ×1
list ×1
regex ×1
string ×1
typescript ×1
xml ×1
xpath ×1