小编Tun*_*caf的帖子

将long.MaxValue转换为int并将float.MaxValue转换为int有什么区别?

我试图了解一些数据类型和转换之间的差异.

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.MaxValueint它,则返回-1.

这两个铸件有什么区别?我认为第一个也假设返回-2147483648而不是-1.

c# types casting

12
推荐指数
3
解决办法
2422
查看次数

无法从使用中推断出Func <T> Inkover错误.尝试显式指定类型参数

我一直在努力解决委托问题.我发送一个方法作为参数,它不获取参数并返回泛型类型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)

.net c# asp.net-mvc delegates func

2
推荐指数
1
解决办法
1051
查看次数

标签 统计

c# ×2

.net ×1

asp.net-mvc ×1

casting ×1

delegates ×1

func ×1

types ×1