MSDN说:
当用作修饰符时,new关键字显式隐藏从基类继承的成员.隐藏继承的成员时,该成员的派生版本将替换基类版本.虽然您可以在不使用new修饰符的情况下隐藏成员,但结果是警告.如果使用new来显式隐藏成员,则会抑制此警告并记录派生版本旨在替代的事实.
例:
class Base
{
int value;
virtual bool Foo()
{
value++;
}
}
class Derived : Base
{
int value;
override bool Foo()
{
value++;
}
}
Run Code Online (Sandbox Code Playgroud)
我是否必须new向Derived.value声明添加修饰符?有什么变化?
我的字符串是外语.我使用以下正则表达式:
$str = '?? ???? ??? ??? ?????';
$word = '???';
$cont = preg_match_all("/.{0,80}[^\s]*?".preg_quote($word)."[^\s]*?.{0,80}/si",$str,$matched);
print_r($matched);//returns Array ( [0] => Array ( ) ) ..
Run Code Online (Sandbox Code Playgroud)
.
......但如果我设定:
$word = "???";//returns Array ( [0] => Array ( [0] => ?? ???? ??? ??? ????? ) )
Run Code Online (Sandbox Code Playgroud)
我能做些什么才能在外语中使用I修饰符?
在java中可以做这样的事情吗?
static public final {
String A = "a...";
int B = 3;
boolean C = true;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑:对不起我在我的例子中犯了一个错误..我不需要只有字符串..
我有以下代码
function redireectIfNeeded(){
$url = $_SERVER["REQUEST_URI"];
if(preg_match("/\.php/$", $url))
header("Location: ".preg_replace("/\.php/",$url));
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误.
[24-Jul-2012 19:14:18] PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Unknown modifier '$' in ../dbc.php on line 223
Run Code Online (Sandbox Code Playgroud)
我知道我需要在某处使用分隔符,但我尝试过的任何东西都无法正常工作.谁能告诉我我需要做什么?
<? php
$Src = 'images/pages/clients/logos/clnt_aljareera_img.jpg';
$pttn= '/&Src:'.$Src.'/';
$string=preg_replace($pttn,'',$string,1);
?>
Run Code Online (Sandbox Code Playgroud)
//输出错误:未知修饰符'p'
我不明白这样的包修饰符(不是注释):
public package foo;
public class Bar {
}
Run Code Online (Sandbox Code Playgroud)
他们有什么意义吗?
我创建了一个具有许多公共属性的基类,并且使用得非常完美.现在我想使用这个类来派生其他类,但我不希望它的一些属性暴露在继承它的派生类之外.有没有办法让公共基类的属性不能暴露在它的派生类之外.(要隐藏的属性是公共的,因为它们在其他继承它的类中使用.)任何帮助都将高度重视.
public class This_testing {
int x,y;
public This_testing(int x,int y){ //Why modifier void here would cause exception?
this.x=x;
this.y=y;
}
public static void main(String [] args){
This_testing t =new This_testing(40,50);
System.out.println(t.x+" "+t.y);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么对构造函数This_testing使用修饰符void会导致以下异常:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code -
constructor This_testing in class practice.This_testing cannot be applied to given types;
required: no arguments
found: int,int
reason: actual and formal argument lists differ in length
at practice.This_testing.main(This_testing.java:13)
Run Code Online (Sandbox Code Playgroud) 我需要C Primer Plus的练习帮助.
编写一个请求您的名字的程序,并使用它执行以下操作:在比名称宽三个字符的字段中打印它
#include<stdio.h>
#include<string.h>
int main()
{
char a[40];
int p,v=0;
printf("Enter your first name: \n");
scanf("%s",a);
p= strlen(a);
v==p+3;
printf("%s",a);
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用什么作为宽度的修饰符我应该在%和s之间添加什么?
在Josh Smith的本教程中,字段被定义为readonly:
public class CustomerRepository
{
readonly List<Customer> _customers;
...
public CustomerRepository(string customerDataFile)
{
_customers = LoadCustomers(customerDataFile);
}
...
}
Run Code Online (Sandbox Code Playgroud)
以后只读_customers更新列表:
public void AddCustomer(Customer customer)
{
if (customer == null)
throw new ArgumentNullException("customer");
if (!_customers.Contains(customer))
{
_customers.Add(customer);
if (this.CustomerAdded != null)
this.CustomerAdded(this, new CustomerAddedEventArgs(customer));
}
}
Run Code Online (Sandbox Code Playgroud)
如何允许以及使用readonly有什么意义?