我有这样的事情:
public [What Here?] GetAnything()
{
Hello hello = new Hello();
Computer computer = new Computer();
Radio radio = new Radio();
return radio; or return computer; or return hello //should be possible?!
}
Run Code Online (Sandbox Code Playgroud)
我有一个方法,这个方法有时会返回不同类型的值(类).
我怎么能这样做,以后再使用变量,是radio.Play(); 到目前为止?
我需要使用泛型吗?怎么样?
我正在编写一个应用程序,我在其中定义了很多类型为Boolean的属性:
private bool kajmak = true;
public bool Kajmak
{
get { return kajmak ; }
set { kajmak = value; FirePropertyChanged(() => Kajmak); }
}
Run Code Online (Sandbox Code Playgroud)
如你所见,我在开始时就设定kajmak了...... - true原因是无关紧要的 - .(您可能知道bool变量的默认值为false).
现在,有没有办法,将a的默认值更改bool为true?所以我会写:
private bool kajmak; //kajmak = true
Run Code Online (Sandbox Code Playgroud)
代替
private bool kajmak = true;
Run Code Online (Sandbox Code Playgroud)
我能做些什么来实现这个目标?
我想打印我的RichTextBox(eintragRichTextBox)的内容我现在有了这段代码:
private void druckenPictureBox_Click(object sender, EventArgs e)
{
PrintDialog printDialog = new PrintDialog();
PrintDocument documentToPrint = new PrintDocument();
printDialog.Document = documentToPrint;
if (printDialog.ShowDialog() == DialogResult.OK)
{
StringReader reader = new StringReader(eintragRichTextBox.Text);
documentToPrint.Print();
documentToPrint.PrintPage += new PrintPageEventHandler(DocumentToPrint_PrintPage);
}
}
private void DocumentToPrint_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
StringReader reader = new StringReader(eintragRichTextBox.Text);
float LinesPerPage = 0;
float YPosition = 0;
int Count = 0;
float LeftMargin = e.MarginBounds.Left;
float TopMargin = e.MarginBounds.Top;
string Line = null;
Font PrintFont = this.eintragRichTextBox.Font;
SolidBrush PrintBrush …Run Code Online (Sandbox Code Playgroud) 我想在Settings.settings中保存用户设置.我想在运行时创建新的Settings/Rows,但是我听说,这是不可能的,所以我想,我可以将这些东西保存在SettingsFile的字符串列表中,但是我必须使用哪种类型?
System.Collections.Generic.List<String>是不知道的并且
System.Collections.Specialized.StringCollection不起作用(Visual Studio在选择此oO时抛出异常)
我能做什么?
我正在编写一个应用程序,我也在使用ADO.NET:
using System.Data.OracleClient;
Run Code Online (Sandbox Code Playgroud)
代码示例:
try{
OracleConnection myOracleConnection = new OracleConnection(connectionString);
myOracleConnection.Open();
OracleCommand command = myOracleConnection.CreateCommand();
...
}
Run Code Online (Sandbox Code Playgroud)
它有效,但我收到了警告:
Warning 3 'System.Data.OracleClient.OracleCommand' is obsolete: 'OracleCommand has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260'
Run Code Online (Sandbox Code Playgroud)
我有其他选择吗?" Microsoft建议您使用第三方Oracle提供程序. " -
码:
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(path, "*.exe");
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.Created += new FileSystemEventHandler(fileSystemWatcher_Created);
fileSystemWatcher.Deleted += new FileSystemEventHandler(fileSystemWatcher_Deleted);
fileSystemWatcher.EnableRaisingEvents = true;
Run Code Online (Sandbox Code Playgroud)
创建事件工作正常,但删除事件仅在使用SHIFT删除目录/或Exe时触发.但正常删除(移动到回收站)不起作用/触发事件!
如何解决问题?
我已经完成了我的应用程序,现在我正在尝试构建.apk并在我的手机上进行测试(无需调试,在发布模式下).
将链接设置为" 无 "一切正常.这里的问题是,应用程序太大了 - 它的20MB,那就是垃圾.
我读了一篇关于链接的文章: 点击这里
所以我尝试了" Sdk Assemblies Only "和" Sdk and User Assemblies ".第二个选项(两个程序集)直接失败,我甚至无法看到我的应用程序的第一个屏幕(登录).
将链接设置为" 仅限Sdk Assemblies "后,我可以进入第一个屏幕(Loginscreen).该应用程序也是6.73MB什么更好,更有资格.
我现在面临的问题是,当我点击第一个屏幕上的"登录"按钮时,没有任何反应(通常它会将我重定向到下一个活动).
Button被绑定到命令:
public IMvxCommand LoginCommand
{
get
{
return new MvxRelayCommand(DoLogin);
}
}
private void DoLogin()
{
//Do Stuff
}
Run Code Online (Sandbox Code Playgroud)
在DoLogin()中放置一个断点 - 表明它永远不会进入.
那么,我怎么能解决这个问题呢?似乎mvvmcross的功能因任何原因被禁用?
我的主要目标是减少应用程序的大小.
这里重要的是.csproj的必要部分
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<AndroidLinkSkip />
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
Run Code Online (Sandbox Code Playgroud)
我有这个BaseClass:
public class BaseViewModel : INotifyPropertyChanged
{
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Run Code Online (Sandbox Code Playgroud)
和另一个类:
public class SchemaDifferenceViewModel : BaseViewModel
{
private string firstSchemaToCompare;
public string FirstSchemaToCompare
{
get { return firstSchemaToCompare; }
set
{
firstSchemaToCompare = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("FirstSchemaToCompare"));
//StartCommand.RaiseCanExecuteChanged();
}
}
}
Run Code Online (Sandbox Code Playgroud)
PropertyChanged在这里(2次),红色下划线,它说:
Error 1 The event BaseViewModel.PropertyChanged' can only appear on the left hand side of += or …Run Code Online (Sandbox Code Playgroud) 可以说我有以下字符串之一:
"Hello, I'm a String... This is a Stackoverflowquestion!! Here is a Date: 16.03.2013, 02:35 and yeah, plain text blah blah..-."
"This the other string! :) 22.11.2012. Its a Date you see"
"Here we have 2 Dates, 23.12.2012 and 14.07.2011"
Run Code Online (Sandbox Code Playgroud)
从字符串(in DateTime)中获取这些日期的最佳和最快方法是什么?
(仅在字符串中出现第一个日期)
理想的回报:
String 1: 16.03.2013 (as a DateTime)
String 2: 22.11.2012 (" ")
String 3: 23.12.2012 (" ")
Run Code Online (Sandbox Code Playgroud)
所以我会调用一个方法,如:
DateTime date1 = GetFirstDateFromString(string1);
Run Code Online (Sandbox Code Playgroud) 我想存储用户设置。它们是在运行时创建的,应在重新启动应用程序后读取。
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
var property = new SettingsProperty("Testname");
property.DefaultValue = "TestValue";
Settings.Default.Properties.Add(property);
Settings.Default.Save();
}
Run Code Online (Sandbox Code Playgroud)
此时,设置已存储,我可以访问它。
重新启动应用程序后,新创建的设置就消失了:
public MainForm()
{
InitializeComponent();
foreach (SettingsProperty property in Settings.Default.Properties)
{
//Setting which was created on runtime before not existing
}
}
Run Code Online (Sandbox Code Playgroud)
尝试这件作品:Settings.Default.Reload();对结果没有任何影响。我也尝试过类似这里描述的其他东西,但它们都不适合我。