Tag: C#的

如何从HttpPost创build操作方法中知道选中的checkbox?

我与Student之间有多对多的关系。 链接实体集是Enrollment 。 为了简单起见,它们都被定义如下。 楷模 public class Course { public int Id { get; set; } public string Title { get; set; } public virtual ICollection<Enrollment> Enrollments { get; set; } } public class Enrollment { public int Id { get; set; } public int StudentId { get; set; } public int CourseId { get; […]

为什么在C ++中打印一个未初始化的variables?

为什么打印32767 (或其他一些随机数)? 什么是std::cout打印? 为什么它不是NULL (或0 )? int main() { int a; std::cout << a; }

JSON.net直接从oledbconnection序列化

我目前有一个处理程序,它将文件path和tabname作为一个excel文件,将文件处理成一个数据表,然后将表序列化成一个jsonstring以返回。 这是工作,直到我尝试处理大文件,然后我得到一个内存不足的例外。 我想这会减less内存使用,如果我没有加载到数据表第一,并直接加载到JSONstring。 但是,我一直无法find如何做到这一点的任何例子。 我可以直接从OleDbConnection串行到一个string? 怎么样? public void ProcessRequest(HttpContext context) { string path = context.Request["path"]; string tableNames = context.Request["tableNames"]; string connectionString = string.Empty; if (path.EndsWith(".xls")) { connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}; Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""", path); } else if (path.EndsWith(".xlsx")) { connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}; Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1""", path); } DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb"); […]

展开循环工作,for循环不起作用

我有一些我不明白的行为。 展开的循环正常工作! 循环抛出IndexOutOfRangeExceptions。 debugging显示有0..9个teamButton和0..9个卡片c [i]。 🙁 private void Awake() { InitCards(); // This works! teamButtons[0].onClick.AddListener(() => SetCard(c[0])); teamButtons[1].onClick.AddListener(() => SetCard(c[1])); teamButtons[2].onClick.AddListener(() => SetCard(c[2])); teamButtons[3].onClick.AddListener(() => SetCard(c[3])); teamButtons[4].onClick.AddListener(() => SetCard(c[4])); teamButtons[5].onClick.AddListener(() => SetCard(c[5])); teamButtons[6].onClick.AddListener(() => SetCard(c[6])); teamButtons[7].onClick.AddListener(() => SetCard(c[7])); teamButtons[8].onClick.AddListener(() => SetCard(c[8])); // This yields an IndexOutOfRangeException for (int i = 0; i < 9; ++i) […]

澄清需要关于getchar()和换行符

我对使用getchar()从用户读取字符input有疑问。 char char1, char2; char1 = getchar(); char2 = getchar(); 我需要从用户input2字符。 在这种情况下,如果用户input字符'A'后跟一个newline ,然后input字符'B' ,那么存储在char2将是换行符还是字符'B' ? 我在Windows上的CodeBlocks上试过,而char2实际上存储了换行符,但是我打算存储字符'B' 。 我只想知道预期的行为是什么,是否依赖于编译器? 如果是这样,涡轮C和鸣响之间有什么区别呢?

如何比较颜色对象,并得到最接近的颜色在颜色?

比方说,我有一个颜色的arrays(整个色谱,从红色到红色)。 较短的版本将如下所示: public Color[] ColorArray = new Color[360] { Color.FromArgb(255, 245, 244, 242), Color.FromArgb(255, 245, 244, 240), Color.FromArgb(255, 245, 244, 238) } 现在如果我有一个单独的 Color object (Color c = Color.FromArgb(255, 14, 4, 5)) 我怎样才能得到最接近所选颜色的数组中的值? 这甚至有可能吗?

从'const char *'无效转换为'char'

我正在尝试用空格replacestring中的某个字符使用下面的代码行: str[i] = " "; 怎样才能实现这个没有得到问题的标题中的错误?

为什么我不能写string,而我*可以*写入string对象?

如果我定义下面的东西, char *s1 = "Hello"; 为什么我不能做下面的事情, *s1 = 'w'; // gives segmentation fault …why??? 如果我做下面的事情怎么办 string s1 = "hello"; 我可以做下面的事吗, *s1 = 'w';

如何在我的属性中设置dynamic值

我想将一个dynamicvariables作为parameter passing给我的属性。 这里我想使用Environment.MachineName,看下面的代码: public interface IMonitoringViewModelConfiguration : IConfigurationContainer { [ConfigurationKey("MonitoringService", Environment.MachineName)] string ConnectionString { get; } } 但是我得到这个错误:错误1一个属性参数必须是一个常量expression式,typeofexpression式或数组创buildexpression式属性参数typesAbc.ServiceBus.Monitoring.ViewModel 有没有任何解决方法尽可能干净,以通过我的Environment.MachineName? 谢谢。 约翰 PS:我发现了一些关于这个案例的文章,但是它已经被写入了2 – 3年前。 但是今天,来自.NET 4.0的clr是否提供了一些很好的解决scheme?

Math.Pow(等等)实际上是如何工作的

所以我在Google上search了很长时间,几乎找不到任何东西。 我从这个URL中发现了一些关于Math.Pow可能实现的信息,但是它们是不准确的,例如这个代码 public static double PowerA(double a, double b) { int tmp = (int)(BitConverter.DoubleToInt64Bits(a) >> 32); int tmp2 = (int)(b * (tmp – 1072632447) + 1072632447); return BitConverter.Int64BitsToDouble(((long)tmp2) << 32); } static void Main(string[] args) { double x = 12.53, y = 16.45; Console.WriteLine(Math.Pow(x, y)); Console.WriteLine(PowerA(x, y)); } 提供输出: 1,15158266266297E+18 8,9966384455562E+17 所以不准确 我在想,它是一个系列的总和,但我不知道肯定。