这行代码的作用是什么? “description =((string [])result [0])[2];”

时间:2015-11-21 08:47:02

标签: c#

我有一个sql数据库,我想使用它的特定列。下面的代码显示了第三列的匹配项,我只想知道代码中((string[])result[0])[2]的确切内容。

注意:“SingleSelectWhere”功能选择与“word”列中“bag”字匹配的记录。

db.OpenDB("English.db");
ArrayList result = db.SingleSelectWhere("petdef", "*", "word", "=", "'bag'");
if(result.Count > 0)
{
    description = ((string[])result[0])[2];
}
db.CloseDB();

1 个答案:

答案 0 :(得分:1)

如果您不知道代码的作用,请尝试将其拆分为更多可读代码。码。如果我们采用这一行:var result1 = result; var result2 = result[0]; var result3 = (string[])result2; var description = result3[2]. 我们可以这样做:

result

如果将断点设置为第一行,只需启动调试并查看每个步骤/变量包含的内容。就像小费一样。

答案:它使用名为-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:nil]; if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) { [self.view makeToast:@"Saving Captured Image!" duration:2.0f position:@"top"]; UIImage *image = info[UIImagePickerControllerOriginalImage]; [self performSelectorInBackground:@selector(saveImage:) withObject:image]; } } - (void) saveImage : (UIImage *) image { // image detail // NSData *data = UIImagePNGRepresentation(image); NSData *data = UIImageJPEGRepresentation(image, 1.0f); NSString *imagePath = [self pathForMedia:MediaTypeImage name:[self getImageName:data]]; //WRITE FILE BOOL saved = [data writeToFile:imagePath atomically:YES]; if (!saved) return; //Now save: `imagePath` to core Data. } - (NSString *) getImageName : (NSData *) imageData { return [NSString stringWithFormat:@"%@.%@",[self getUniqueId], [self contentTypeForImageData:imageData]]; } - (NSString *) pathForMedia : (MediaType) type name : (NSString *) name{ NSString *foldername = [NSString stringWithFormat:@"/%@/%@", ((type == MediaTypeImage) ? @"Photos" : @"Videos"), name]; return [[self getUserDocumentDir] stringByAppendingPathComponent:foldername]; } - (NSString *)contentTypeForImageData:(NSData *)data { uint8_t c; [data getBytes:&c length:1]; switch (c) { case 0xFF: return @"jpg"; case 0x89: return @"png"; case 0x47: return @"gif"; case 0x49: break; case 0x42: return @"bmp"; case 0x4D: return @"tiff"; } return nil; } - (NSString *) getUniqueId { CFUUIDRef unqiueId = CFUUIDCreate(NULL); CFStringRef string = CFUUIDCreateString(NULL, unqiueId); CFRelease(unqiueId); return [(__bridge NSString*)string stringByReplacingOccurrencesOfString:@"-"withString:@""]; } 的数组/列表并返回第一个元素。比你把它投射到一个字符串数组,最后选择thrid元素(基于零的索引!)。希望这会有所帮助。