我需要在网站上分享动态创建的网址到facebook和linkedin.我正在分享到Facebook正确,并已设置所有需要的og标签.但对于linkedin来说它不起作用.
这是我的网址:https://www.fourthambit.com/blogs_fa/102048
它在Facebook中正确解析并正确显示预览.
但同样的链接在linkedin中不起作用.
我错过了什么吗?
设置所有需要的元标记:
<meta property="og:title" content="Indian Media: Then.... Now... and Later" />
<meta content="Sensationalism has become synonymous with the Indian Media, especially Television. In 2008 dur..." name="description" />
<meta property="og:description" content="Sensationalism has become synonymous with the Indian Media, especially Television. In 2008 dur..." />
<meta content="Academic network" name="keywords" />
<meta property="og:image" content="https://www.fourthambit.com/article/getarticlephoto/big/ZGNlZQD4/0/102/20150807050217-12217198186.jpg" />
<img src="https://www.fourthambit.com/article/getarticlephoto/big/ZGNlZQD4/0/102/20150807050217-12217198186.jpg" style="display: none !important;" />
<meta property="og:type" content="website" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
Run Code Online (Sandbox Code Playgroud)
这是我尝试在linkedin更新状态栏textarea中查看预览时的ajax调用.
https://www.linkedin.com/sharing/api/url-preview?url=https://www.fourthambit.com/blogs_fa/102048
我正在尝试在 C# 中计算 4203708359 弧度的余弦:
var x = (double)4203708359;
var c = Math.Cos(x);
Run Code Online (Sandbox Code Playgroud)
(4203708359可以用双精度精确表示。)
我越来越
c = -0.57977754519440394
Run Code Online (Sandbox Code Playgroud)
Windows 的计算器给出
c = -0.579777545198813380788467070278
Run Code Online (Sandbox Code Playgroud)
Linux 上的PHPcos(double)
函数(内部仅使用cos(double)
C 标准库)给出:
c = -0.57977754519881
Run Code Online (Sandbox Code Playgroud)
cos(double)
使用 Visual Studio 2017 编译的简单 C 程序中的C函数给出
c = -0.57977754519881342
Run Code Online (Sandbox Code Playgroud)
Math.cos()
以下是C# 中的定义:https: //github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Math.cs#L57-L58
它似乎是一个内置函数。我(还)没有深入研究 C# 编译器来检查其有效编译的内容,但这可能是下一步。
同时:
为什么我的 C# 示例中的精度这么差,我该怎么办?
难道只是因为 C# 编译器中的余弦实现无法很好地处理大整数输入吗?
编辑 1:Wolfram Mathematica 11.0:
In[1] := N[Cos[4203708359], 50]
Out[1] := -0.57977754519881338078846707027800171954257546099993
Run Code Online (Sandbox Code Playgroud)
编辑2:我确实需要这种级别的精度,并且我已经准备好为了获得它而走很远。如果存在一个支持余弦的好库(到目前为止我的努力还没有实现),我很乐意使用任意精度库。
编辑3:我在 coreclr 的问题跟踪器上发布了问题: https: //github.com/dotnet/coreclr/issues/12737
double a, b = ...;
Run Code Online (Sandbox Code Playgroud)
是以下C#-statements
!(a > b)
Run Code Online (Sandbox Code Playgroud)
和
a <= b
Run Code Online (Sandbox Code Playgroud)
相当于还是有任何数字警告?
我想使用lambda表达式按任意列/字段名称对任意实体类型的IEnumerable进行排序。
我有这个排序功能:
public static IEnumerable<T> SortByFieldName<T>(IEnumerable<T> target, string sortPropertyName, string sortDirection)
{
if (!String.IsNullOrEmpty(sortPropertyName))
{
Expression<Func<T, object>> sortExpression = GetSortLambda<T>(sortPropertyName);
switch (sortDirection.ToLower())
{
case "a":
return target.AsQueryable<T>().OrderBy(sortExpression);
case "d":
return target.AsQueryable<T>().OrderByDescending(sortExpression);
default:
return target;
}
}
return target;
}
Run Code Online (Sandbox Code Playgroud)
用此函数创建表达式(从此处的另一个答案修改)
public static Expression<Func<T,object>> GetSortLambda<T>(string propertyPath)
{
var param = Expression.Parameter(typeof(T), "p");
var parts = propertyPath.Split('.');
Expression parent = param;
foreach (var part in parts)
{
parent = Expression.Property(parent, part);
}
var sortExpression = Expression.Lambda<Func<T, object>>(parent, param);
return sortExpression;
}
Run Code Online (Sandbox Code Playgroud)
对于解析为字符串的任何属性路径,此操作均符合预期,但是对于Integer(对于Boolean而言,更不频繁),将生成以下错误(在Int32属性的情况下): …
假设我有一个C#线程做一些阻塞IO并等待它完成.现在OS调度程序为它提供了CPU时间.它会立即返回还是只是被线程无效使用?或者也许完全不同的东西?
我在Win7/64bit上使用PowerShell 3.我试图用这个命令使用Excel(32位)的.NET:[microsoft.office.interop.excel.xlfileformat]我得到这个错误:无法找到类型microsoft.office.interop.excel.xlfileformat:确保加载包含此类型的程序集.我使用Win7/32bit之前没有出现此错误.也许有人知道如何解决这个问题?
我用MemoryMappedFile
as msdn做了一个简单的测试:
2个进程,1个内存映射文件:
using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("testmap", 10000))
{
bool mutexCreated;
Mutex mutex = new Mutex(true, "testmapmutex", out mutexCreated);
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
BinaryWriter writer = new BinaryWriter(stream, Encoding.UTF8);
writer.Write("1");
}
mutex.ReleaseMutex();
Console.WriteLine("Start Process B and press ENTER to continue.");
Console.ReadLine();
mutex.WaitOne();
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
BinaryReader reader = new BinaryReader(stream, Encoding.UTF8);
Console.WriteLine("Process A says: {0}", reader.ReadString());
Console.WriteLine("Process B says: {0}", reader.ReadString());
}
mutex.ReleaseMutex();
}
Run Code Online (Sandbox Code Playgroud)
using …
Run Code Online (Sandbox Code Playgroud) 我很好奇我是否忽略了一些明显的东西:我经常使用List<T>
,而且我经常需要检查它是否包含任何值.我打电话List<T>.Count()
来查看计数是否大于0.这感觉就像一个昂贵的操作,只是想看看它是否包含任何值.
检查这个有一些被忽视的方法吗?一个IsEmpty()
样的事情?
问:我怎样才能最有效地转换Dictionary<string, int>
to a Dictionary<int, List<string>>
?
例
var input = new Dictionary<string, int>() { {"A", 1}, {"B", 1}, {"C", 2} ...
Dictionary<int, List<string>> result = Transform(input)
Assert.IsTrue(result, { {1, {"A", "B"}}, {2, {"C"}} ... });
Run Code Online (Sandbox Code Playgroud) 在.NET中是否有一个方法,它会在一个字符串的路径末尾自动附加一个反斜杠?
就像是:
var path = @"C:\Windows";
path = Path.GetPathWithSeperatorAtTheEnd(path);
Console.WriteLine(path);
// outputs C:\Windows\
Run Code Online (Sandbox Code Playgroud)
我现在做的是:
if (!path.EndsWith(@"\")) path += @"\";
Run Code Online (Sandbox Code Playgroud)
编辑:我想要实现的是,如果我将文件名附加到一个我不需要担心的路径,那就会发生这样的事情.或者是否有另一种方法而不是追加路径和文件名?
var fullFilename = path + filename;
// path : C:\Windows
// filename: MyFile.txt
// result : C:\WindowsMyFile.txt
Run Code Online (Sandbox Code Playgroud) 我有一个代码块(见下文).因此,如果我在工作1中得到异常,代码执行将继续在哪里,并且与工作2相同.它会继续工作B还是在foreach
-loop中开始新的转向?a中catch {}
有没有a有什么区别return
?
foreach (var item in arr)
{
//// Work A
try
{
// work 1
}
catch { }
try
{
// work 2
}
catch { return; }
//// work B
}
Run Code Online (Sandbox Code Playgroud)