我浪费时间思考为什么这个程序运行不正常,没有成功.它始终打印"角色是一个特殊的符号".
#include <stdio.h>
int main( void )
{
char character;
printf( "Please type any character and I will tell you what type it is:\n" );
while( 1 )
{
scanf( "%c", &character);
if( character >= 65 && character <= 90 )
printf( "The character is A-Z\n" );
else if( character >= 97 && character <= 122 )
printf( "The character is a-z\n" );
else if( character >= 48 && character <= 57 )
printf( "The character is 0-9\n" );
else …Run Code Online (Sandbox Code Playgroud) 程序
#include <stdio.h>
int main(void)
{
int i, j, k;
i = 1; j = 1; k = 1;
printf("%d ", ++i || ++j && ++k);
printf("%d %d %d", i, j, k);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
结果
1 2 1 1
Run Code Online (Sandbox Code Playgroud)
我期待1 1 2 2.为什么?因为&&优先于||.所以我按照这些步骤:1)j加1,所以j现在值2 ... 2)k加1,所以k现在值2 ... 3)2 && 2,评估为1 ... 4)不需要进一步评估作为||的右操作数 是的,所以整个表达式必须是真的,因为逻辑表达式的短路行为......
为什么我错了?
我收到此错误消息"由于其保护级别无法访问"在最后一行,但我已检查,一切似乎是公开的.可能有什么不对?
using System;
using System.Collections.Generic;
namespace Test
{
class Sneakers
{
public string _brand;
public Sneakers(string brand)
{
_brand = brand;
}
public string Show()
{
return "The brand is: " + _brand;
}
public static string Show(Sneakers mySneak)
{
return mySneak.Show();
}
}
class Program
{
static void Main(string[] args)
{
Sneakers mySneak = new Sneakers("Nike");
Dictionary<Sneakers, double> collection = new Dictionary<Sneakers, double>();
collection.Add(mySneak, 10);
foreach (KeyValuePair<Sneakers, double> item in collection)
{
Console.WriteLine(Sneakers.Show(item.key));//HERE IS THE ERROR IN "key"
} …Run Code Online (Sandbox Code Playgroud) 我正在关注官方的Angular 2教程,它使用的导航功能与routerLink非常相似.他们之间有什么区别?哪个用的?
this.router.navigate(['/detail', this.selectedHero.id]);
Run Code Online (Sandbox Code Playgroud)
[routerLink]="['/detail', hero.id]"
Run Code Online (Sandbox Code Playgroud) 我正在读一本初学者的C#书.一切都很顺利定义像这样的对象:
BaseClass foo = new BaseClass();
Run Code Online (Sandbox Code Playgroud)
但是作者没有任何解释就改变了这样的定义:
MiClass foo = new DerivedClass();
Run Code Online (Sandbox Code Playgroud)
我想在书本或互联网上了解这一点,但我不知道用什么词来搜索这个主题.
c ×4
c# ×3
angular ×1
class ×1
definition ×1
derived ×1
dictionary ×1
if-statement ×1
linkage ×1
object ×1
scope ×1
while-loop ×1