小编San*_*eep的帖子

为什么编译器不能决定类型

我很想知道为什么我们需要为小数类型追加m或M?

文档说没有隐式转换

我认为编译器有足够的信息,因为我们声明Decimal关键字.

可以请一些人解释为什么编译器不能确定该值应该被视为十进制而不是双精度.

.net c# implicit-conversion

5
推荐指数
1
解决办法
107
查看次数

进程地址空间与虚拟内存

根据我的理解,通过阅读几篇文章,我假设进程地址空间(PAS)和虚拟内存(VM)是相同的.我的理解有缺陷吗?有人可以对此有所了解并点亮我吗?我很迷惑.

我理解进程地址空间与Ram或物理内存无关.

但只是对PAS和VM感到困惑.

language-agnostic windows memory-management

5
推荐指数
1
解决办法
2811
查看次数

理解弱参考

我有以下启用ARC的代码

@property (nonatomic, weak) NSArray *a;
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.a = @[@1, @2];
    NSLog(@"ab is %@", self.a); //prints details of array
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{

    [super didReceiveMemoryWarning];
    for (id element in self.a) { //empty here
        NSLog(@"blah");
    }
    // Dispose of any resources that can be recreated.
}
Run Code Online (Sandbox Code Playgroud)

这是我用过的唯一的地方self.a.这是我编写的一个测试程序,用于调试我的一个问题.

当我模拟内存警告self.a消失?为什么?

objective-c automatic-ref-counting

5
推荐指数
1
解决办法
1万
查看次数

为什么带有多个分号的代码会编译?

我很想知道为什么这是允许的.

int i=0;;
Run Code Online (Sandbox Code Playgroud)

我偶然输入了那个.但该计划编制.经过很多天我打字后才注意到它;;

之后我尝试了不同的符号 ~, !, : etc etc

为什么不允许第一个允许的地方.

只是好奇才知道.

c# syntax

4
推荐指数
2
解决办法
233
查看次数

收集被修改; 枚举操作可能无法执行

这个问题很多时候都在这个论坛上被问到.我知道问题的解决方案.但我很想知道为什么"修改集合时无法执行枚举操作"

        List<string> list = new List<string>();

        list.Add("a");

        list.Add("b");

        int[] array = new int[6] { 1, 2, 3, 4, 5, 5 };

        HashSet<int> hashSet = new HashSet<int>();

        int i = 0;

        foreach (string s in list)
        {
            list[i] = "test";

            i++;
        }
Run Code Online (Sandbox Code Playgroud)

但是当我将列表更改为list.toarray有效时.

.net c# collections

4
推荐指数
2
解决办法
3557
查看次数

为什么不调用该方法?

只是想更好地理解这一点.我知道这是因为Deffered Execution

但究竟是什么原因导致该方法无法立即被调用.这是来自JonSkeet的EduLinq.

 public static partial class Enumerable
{
    public static IEnumerable<TSource> Where<TSource>(
        this IEnumerable<TSource> source,
        Func<TSource, bool> predicate)
    {
        if (source == null)
        {
            throw new ArgumentNullException("source");
        }
        if (predicate == null)
        {
            throw new ArgumentNullException("predicate");
        }

        foreach (TSource item in source)
        {
            if (predicate(item))
            {
                yield return item;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我使用它的地方.

List<int> list = new List<int>() { 1, 3, 4, 2, 8, 1 };

var s = list.Where(x => x > 4);

var result = …
Run Code Online (Sandbox Code Playgroud)

linq c#-4.0

4
推荐指数
1
解决办法
166
查看次数

从Task.Continuewith更新UI标签

我正在开发一个Winform应用程序.它MethodBackgroundWorker Thread 启动.对不起.我之前没有提到这一点.

private void Method()
{
 tasks[i] = Task.Factory
           .StartNew(() => fileProcessor.ProcessEachMachine(mdetail))
           .ContinueWith(UpdateLabel, TaskContinuationOptions.OnlyOnRanToCompletion);
}
Run Code Online (Sandbox Code Playgroud)

我有一个长期运行的功能ProcessEachMachine.在延续函数中,UpdateLabel我想访问UIlabel并更新状态.

private void UpdateLabel()
{
   progressLbl.Text = "updated";
}
Run Code Online (Sandbox Code Playgroud)

但标签没有得到更新.如何访问UILabel并更新它的文本.

.net c#

4
推荐指数
1
解决办法
4647
查看次数

UUID Cassandra

我是Cassandra的新手.我试图将一些值插入columnfamily.配置文件中columnfamily的定义如下.

<ColumnFamily Name="CommandQueue"
                    ColumnType="Super"
                    CompareWith="TimeUUIDType"
                    CompareSubcolumnsWith="UTF8Type"/>
Run Code Online (Sandbox Code Playgroud)

当我尝试向我插入值时,我总是得到"InvalidRequestException(为什么:UUID必须正好是16个字节)".

我正在使用batch_mutate()来插入列.

如何将值插入列族.

cassandra

3
推荐指数
1
解决办法
2583
查看次数

为什么我们需要太多执行相同功能的方法?

string s1 = "1234"; 
string s2 = "1234.65"; 
string s3 = null; 
string s4 = "123456789123456789123456789123456789123456789";  

result = Int32.Parse(s1); //-- 1234
result = Int32.Parse(s2); //-- FormatException 
result = Int32.Parse(s3); //-- ArgumentNullException 
result = Int32.Parse(s4); //-- OverflowException 

result = Convert.ToInt32(s1); //-- 1234 
result = Convert.ToInt32(s2); //-- FormatException 
result = Convert.ToInt32(s3); //-- 0 
result = Convert.ToInt32(s4); //-- OverflowException 

success = Int32.TryParse(s1, out result); //-- success => true; result => 1234 
success = Int32.TryParse(s2, out result); //-- success => false; result => 0 …
Run Code Online (Sandbox Code Playgroud)

c#

3
推荐指数
1
解决办法
151
查看次数

将IEnumerable <byte []>转换为byte []

 var  r = from s in tempResult    
          select Encoding.GetEncoding("iso-8859-1").GetBytes(s);
Run Code Online (Sandbox Code Playgroud)

我理解,这会返回IEnumerable<byte[]>,但我正在寻找LINQ方式将整个转换IEnumerable<byte[]>byte[].

c# linq

3
推荐指数
1
解决办法
9717
查看次数