我试图了解一些数据类型和转换之间的差异.
public static void ExplicitTypeConversion2()
{
long longValue=long.MaxValue;
float floatValue = float.MaxValue;
int integerValue = (int) longValue;
int integerValue2 = (int)floatValue;
Console.WriteLine(integerValue);
Console.WriteLine(integerValue2);
}
Run Code Online (Sandbox Code Playgroud)
当我运行该代码块时,它输出:
-1
-2147483648
Run Code Online (Sandbox Code Playgroud)
我知道如果要分配给整数的值大于该整数可以保留的值,则返回整数的最小值(-2147483648).
据我所知,long.MaxValue它比一个整数的最大值大得多,但是如果我转换long.MaxValue为int它,则返回-1.
这两个铸件有什么区别?我认为第一个也假设返回-2147483648而不是-1.
我一直在努力解决委托问题.我发送一个方法作为参数,它不获取参数并返回泛型类型Result<T>.
public Result<Content> GetContents()
{
var contents = new Result<List<TypeLibrary.Content>>();
contents.Object = context.GetContents();
if (contents.Object != null)
{
contents.Success = true;
}
else
{
contents.Success = false;
}
return contents;
}
public static Result<T> Invoker<T>(Func<Result<T>> genericFunctionName) where T : new()
{
Result<T> result;
try
{
//do staff
result = genericFunctionName();
}
catch (Exception)
{
throw;
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
模特是
public class Result<T> where T : new()
{
public bool Success { get; set; }
public string Message …Run Code Online (Sandbox Code Playgroud)