我正在经历一些面试问题,我遇到了如下示例。我尝试了简单输入/输出以及一些逻辑的示例,它工作没有任何问题。
??=include <stdio.h>
int main(void)
??<
printf("Hello");
// Other code lines here
return 0;
??>
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,这没有任何编译问题,并且输出符合要求。
这里的“??=”、“??<”和“??>”有何意义?
我是.net开发的新手,所以请在这里帮助我。
我试图通过xaml数据绑定将值从c#类传递到验证规则。
C#类:
public class NumericDoubleUpDownValueContainerVM : SimpleValueContainerVM<string>
{
public NumericDoubleUpDownValueContainerVM(double value, double minValue, double maxValue, int decimalPlace) : base(value.ToString())
{
this.MinimumValue = minValue;
this.MaximumValue = maxValue;
this.DecimalPlaces = decimalPlace;
}
public double MinimumValue { get; set; }
public double MaximumValue { get; set; }
public int DecimalPlaces { get; set; }
public override void UpdatePropertyValue(object value, string propertyName = "")
{
this.Value = Convert.ToString(value);
}
}
Run Code Online (Sandbox Code Playgroud)
这SimpleValueContainerVM<T>是一个通用类,用于从相应的UI元素获取和设置值。
XAML代码:
<DataTemplate DataType="{x:Type VM:NumericDoubleUpDownValueContainerVM}" >
<Grid x:Name="Maingrid" >
<WPFStyles.CustomControls:NumericUpDown Minimum="{Binding …Run Code Online (Sandbox Code Playgroud) 我有一个 C++ 项目,其目标平台版本类型为 10.0.15063.0,目标平台为 Windows 10。
我尝试创建一个用于构建和发布工件的天蓝色管道,但我面临使用 choco 安装特定版本的 Windows sdk(即 10.0.15063.x)的问题。
尝试过的命令:
choco install windows-sdk-10.0 --version=10.0.15063
Run Code Online (Sandbox Code Playgroud)
我收到错误消息,指出在列出的源中找不到该包。有什么办法可以解决这个问题吗?
我正在尝试使用一个枚举,其中枚举值之一被定义为宏。
enum class Method
{
GET,
POST,
PUT,
HEAD
// I want to add DELETE
};
Run Code Online (Sandbox Code Playgroud)
该枚举将在值转换为字符串之前使用。
但是当我添加它时,它说这被定义为我在类中使用的文件DELETE之一中的宏- ..hwinnt.h
在 中winnt.h,DELETE定义为:
#define DELETE (0x00010000L)
Run Code Online (Sandbox Code Playgroud)
编译器给出一个错误,指出“需要一个标识符”。
我不想更改正在使用枚举并将其转换为字符串的代码。
如何将此DELETE值添加到我的枚举中?
我们考虑一个样本层次结构
class BaseClass{}
class ChildClass1 : BaseClass{}
class ChildClass2 : BaseClass{}
Run Code Online (Sandbox Code Playgroud)
现在我有一个BaseClass类型的通用列表
List<BaseClass> sampleList = new List<BaseClass>();
Run Code Online (Sandbox Code Playgroud)
在这个列表中,我添加了Both ChildClass1和的对象ChildClass2.
现在,当访问这些对象时,我想对不同类型的对象进行不同的操作.我可以轻松地使用if-else并检查对象是否是所需类型.
class SampleClass
{
int Property{get;set;}
List<BaseClass> sampleList = new List<BaseClass>();
void DoCalculations()
{
foreach(var obj in sampleList)
{
if(obj is ChildClass1){//Do something to this.Property}
else if(obj is ChildClass2){//Do Somethingto this.Property}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是由于复杂性和性能问题,我想避免使用if-elseor switch(我的实际案例包含大量的派生类).
因此,为了解决这个问题,我想出了一种方法来重载具有相同名称但不同类型的方法(每种方法都适用于每种派生类型).
我想过以某种方式迭代并将BaseClass转换为ChlidClass对象并将其传递给DoSomething()方法,重载本身将负责执行哪个操作.但是,我无法从BaseClass获取ChildClass类型的对象以动态工作.
我试过的是:
class SampleClass
{
int Property{get;set;}
List<BaseClass> sampleList = new List<BaseClass>();
public void …Run Code Online (Sandbox Code Playgroud) 给定一个字符串,我想根据索引交换字符串中的 2 个字符。
输入:str =“你好”索引1 = 1 索引2 = 4
输出:str =“Holle”
但是当我直接尝试更新字符串字符时:
str[1] = //Assign something
Run Code Online (Sandbox Code Playgroud)
它给出了错误 ->
无法分配属性或索引器“string.this[int]”——它是只读的
所以我写了一个函数,在执行交换操作之前将字符串转换为字符数组。
static string SwapChars(String str, int index1, int index2)
{
char[] strChar = str.ToCharArray();
char temp = strChar[index1];
strChar[index1] = strChar[index2];
strChar[index2] = temp;
return new String(strChar);
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想知道该函数的时间复杂度是多少。我认为这是 O(n),因为 char 数组和字符串正在被构造为新的,其中 n 是传递的字符串的长度。还有其他方法可以以更好的性能执行此操作吗?