我在以下文件夹中安装了Java 1.7.0 C:\Program Files\Java.我的操作系统是带有Service Pack 3的Windows XP(版本2002).
我设置的环境变量是:
CLASSPATH:C:\Program Files\Java\jdk1.7.0\jre\lib\rt.jar;
路径: C:\Program Files\Java\jdk1.7.0\bin;
JAVA_HOME:C:\Program Files\Java;
我在这里介绍了我系统中的类名.
接下来我写了一个程序HelloWorld.java:
import java.io.*;
class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
Run Code Online (Sandbox Code Playgroud)
当我编译使用javac HelloWorld.java它时,编译正常.
但在我发出后,我java HelloWorld遇到了以下错误:
Error: Could not find main class HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:198)
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:299)
at java.net.URLClassLoader$1.run(URLClassLoader.java:288)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:287)
at java.lang.ClassLoader.loadClass(ClassLoader.java:422)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:325)
at java.lang.ClassLoader.loadClass(ClassLoader.java:355)
at …Run Code Online (Sandbox Code Playgroud) 我有一个函数只返回一系列日期的星期五
public static List<DateTime> GetDates(DateTime startDate, int weeks)
{
int days = weeks * 7;
//Get the whole date range
List<DateTime> dtFulldateRange = Enumerable.Range(-days, days).Select(i => startDate.AddDays(i)).ToList();
//Get only the fridays from the date range
List<DateTime> dtOnlyFridays = (from dtFridays in dtFulldateRange
where dtFridays.DayOfWeek == DayOfWeek.Friday
select dtFridays).ToList();
return dtOnlyFridays;
}
Run Code Online (Sandbox Code Playgroud)
功能目的: "从指定的周数到StartDate的日期列表,即如果startdate是2010年4月23日,周数是1,那么程序应该返回日期从2010年4月16日到startddate".
我把这个函数称为:
DateTime StartDate1 = DateTime.ParseExact("20100430", "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
List<DateTime> dtList = Utility.GetDates(StartDate1, 4).ToList();
Run Code Online (Sandbox Code Playgroud)
现在要求发生了一些变化.我只需要找出每个月的最后一个星期五.该函数的输入将保持不变.
如果我做
for (int i = 0; i < appSettings.Count; i++)
{
string key = appSettings.Keys[i];
euFileDictionary.Add(key, appSettings[i]);
}
Run Code Online (Sandbox Code Playgroud)
它工作正常。
当我尝试使用相同的东西时
Enumerable.Range(0, appSettings.Count).Select(i =>
{
string Key = appSettings.Keys[i];
string Value = appSettings[i];
euFileDictionary.Add(Key, Value);
}).ToDictionary<string,string>();
Run Code Online (Sandbox Code Playgroud)
我收到编译时错误
无法从用法推断方法“System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)”的类型参数。尝试明确指定类型参数。
任何的想法?
使用 C#3.0
谢谢
如何在C#中将Class转换为字节数组.这是一个托管的,因此以下代码失败
int objsize = System.Runtime.InteropServices.Marshal.SizeOf(objTimeSeries3D);
byte[] arr = new byte[objsize];
IntPtr buff = System.Runtime.InteropServices.Marshal.AllocHGlobal(objsize);
System.Runtime.InteropServices.Marshal.StructureToPtr(objTimeSeries3D, buff, true);
System.Runtime.InteropServices.Marshal.Copy(buff, arr, 0, objsize);
System.Runtime.InteropServices.Marshal.FreeHGlobal(buff);
Run Code Online (Sandbox Code Playgroud)
谢谢
考虑一下
List<int> intList = new List<int> { 1, 2, 3, 4, 5, 6 };
int j = 0;
intList.ForEach(i =>
{
if (i.Equals(1))
{
j = i;
break;
}
}
);
Run Code Online (Sandbox Code Playgroud)
投掷错误:没有封闭的循环,可以打破或继续
但下面的工作
foreach(int i in intList)
{
j = i; break;
}
Run Code Online (Sandbox Code Playgroud)
为什么这样.我犯了什么错
谢谢
如何转换下面的代码
double sumxy = 0;
for (int i = 0; i < x.Count; i++)
{sumxy = sumxy + (x[i] * y[i]);}
Run Code Online (Sandbox Code Playgroud)
通过使用lambda
我正在使用C#3.0.x和y是双数列表
谢谢
我尝试了最好的水平来编写改进的版本但失败了.
inFiles.ToList().ForEach(i =>
{
filePath = inFolder + "\\" + i.Value;
if (i.Key.Equals(replacementFile))
{
replacementCollection = GetReplacementDataFromFile(filePath);
}
else if (i.Key.Equals(standardizationFile))
{
standardizationCollection = GetStandardizationDataFromFile(filePath);
}
});
Run Code Online (Sandbox Code Playgroud)
问题是我不能在这里使用switch case,因为比较变量不是常量.
请帮助改进此代码.
我正在使用C#(3.0).
谢谢
我不知道这是否是一个有效的问题,但我做了一个尝试.
我基本上是一名C#家伙.但是自从过去7天以来,我被要求在java(J2SE 1.4)中工作,而我正在努力.我逐渐对此感兴趣.
我想了解更多关于它的信息,因为我发现C#和Java之间有很多相似之处(我在7天内收集了迄今为止所收集到的内容),我计划引导我的职业生涯.
但是在C#中度过了2年多,然后转向java,如果我需要改变我的工作,这将是未来的问题(比如3/4个月之后).我的意思是我的大部分时间.位于C#并刚刚启动JAVA.那么如果我需要改变平台,技术小组将如何接受我?
谢谢
List<double> y = new List<double> { 0.4807, -3.7070, -4.5582,
-11.2126, -0.7733, 3.7269,
2.7672, 8.3333, 4.7023 };
List<double> d1 = y.ForEach(i => i * 2);
Run Code Online (Sandbox Code Playgroud)
错误:只能将赋值,调用,递增,递减和新对象表达式用作语句
怎么了?
谢谢
可以以更好的方式完成
public static EnumFactorType GetFactorEnum(string str)
{
Standardization e = new Standardization();
switch (str.ToLower())
{
case "beta":
e.FactorType = EnumFactorType.BETA;
break;
case "bkp":
e.FactorType = EnumFactorType.BOOK_TO_PRICE;
break;
case "yld":
e.FactorType = EnumFactorType.DIVIDEND_YIELD;
break;
case "growth":
e.FactorType = EnumFactorType.GROWTH;
break;
case "mean":
e.FactorType = EnumFactorType.MARKET_CAP;
break;
case "momentum":
e.FactorType = EnumFactorType.MOMENTUM;
break;
case "size":
e.FactorType = EnumFactorType.SIZE;
break;
case "stat_fact1":
e.FactorType = EnumFactorType.STAT_FACT_1;
break;
case "stat_fact2":
e.FactorType = EnumFactorType.STAT_FACT_2;
break;
case "value":
e.FactorType = EnumFactorType.VALUE;
break;
}
return e.FactorType;
}
Run Code Online (Sandbox Code Playgroud)
如果我创建一个静态类(比如Constatant)并声明变量之类的 …