Tag: int

是否有Int.isWholeNumber()函数或类似的东西?

我需要检查输入是否为int。 是否有与String.IsNullOrEmpty()类似的函数,就像Int.isWholeNumber()函数一样? 有没有办法在if()语句中validation这个,而不必在之前声明一个int? (正如你需要使用TryParse()) 编辑 我需要validation区号(五个数字)

Linq存储过程问题 – 返回int

我试图用Linq调用一个存储过程,存储过程在SQL中返回值很好,但当我将它拖到我的DBML文件并尝试从我的代码调用它时它返回 无法找到源类型“int”的查询模式的实现。 找不到“选择”。 我查看了其他线程和其他存储过程,由于某些原因而不是使用ISingleResult这是不同的,我似乎也无法更改返回类型。 这是背后的DBML代码 [global::System.Data.Linq.Mapping.FunctionAttribute(Name=”dbo.displayDetails”)] public int displayDetails([global::System.Data.Linq.Mapping.ParameterAttribute(DbType=”VarChar(1)”)] string sex, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType=”Int”)] System.Nullable day, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType=”Int”)] System.Nullable month, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType=”Int”)] System.Nullable year, [global::System.Data.Linq.Mapping.ParameterAttribute(Name=”PostCode”, DbType=”VarChar(10)”)] string postCode, [global::System.Data.Linq.Mapping.ParameterAttribute(Name=”AppTime”, DbType=”DateTime”)] System.Nullable appTime, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType=”Int”)] System.Nullable filter) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), sex, day, month, year, postCode, appTime, filter); return ((int)(result.ReturnValue)); } 我的页面代码正在收到错误 var person = from p in db.displayDetails(sex.ToString(), […]

使用HashSet 创建整数集

我想创建一个使用HashSet表示整数集的类。 我希望它使用该内部容器跟踪集合中包含的值。 到目前为止我做到了这一点: class SetInteger { HashSet intTest= new HashSet(); intTest.Add(1); intTest.Add(2); intTest.Add(3); intTest.Add(4); intTest.Add(5); intTest.Add(6); intTest.Add(7); intTest.Add(8); intTest.Add(9); intTest.Add(10); } 所以,在这里我想我正在为HashSet添加一些值,但是我没有看到它如何跟踪集合中包含的值。 有任何想法吗?

在C#中添加DateTime

是否可以在C#中添加日期? (DateTime.Today.ToLongDateString() + 10) 我试过这个,但它不起作用。

C#如何在类中使用get,set和use enums

我有一个程序,我使用类存储设置。 我需要它来使用set和get函数来更改和存储设置。 我试过这个,但我没有让它发挥作用。 任何人都可以帮我这个吗? private enum _Difficulty { Easy, Normal, Hard }; public void SetDifficulty(Difficulty) { _Difficulty = Difficulty; } public enum GetDifficulty() { return _Difficulty; } 有没有办法在get和set的类中使用enums ? 我还需要bool和int 。

可以从int 数组中获取IntPtr吗?

问候。 在C#中:如果我有一个像这样声明的int []数组 int[] array = new array[size]; 有一种方法可以从这个数组中获取IntPtr吗? 问题是我正在使用EmguCV框架,并且有一个构造函数来创建一个图像,它将IntPtr带到像素数据,以便从数组(int [])构建图像。 Image result = new Image(bitmap.Width,bitmap.Height,stride,”**array.toPointer??**”); 顺便说一句,如果有人能告诉我如何计算步幅,这将是伟大的。

短的一元减去变成一个int?

在下面的: public class p { short? mID; short? dID; } short id = p.mID ?? -p.dID.Value; 编译器给我错误: 错误21无法将类型’int’隐式转换为’short’。 存在显式转换(您是否错过了演员?) 我必须将代码更改为以下代码才能工作: short id = p.mID ?? (short)-p.dID.Value; 好像编译器正在执行类似(int)0 – p.dID.Value,或Int16.operator – 正在返回Int32s …?

++ i C#和C ++中的运算符差异

我有以下用C ++和C#编写的代码 int i=0; ++i = 11; 在此C#编译器带来错误之后 The left-hand side of an assignment must be a variable, property or indexer 但C ++编译器生成此代码时没有错误,我得到了一个值为i的结果11 。 这种差异的原因是什么?

在C#和SQL Server中不同地将int转换为guid

在C#和SQL Server中将int转换为guid时,我得到不同的值。 在C#中我使用这种方法 public static Guid Int2Guid( int value ) { byte[] bytes = new byte[16]; BitConverter.GetBytes( value ).CopyTo( bytes, 0 ); return new Guid( bytes ); } Console.Write( Int2Guid( 1000 ).ToString() ); // writes 000003e8-0000-0000-0000-000000000000 在SQL Server中我使用 select cast(cast(1000 as varbinary(16)) as uniqueidentifier) — writes E8030000-0000-0000-0000-000000000000 他们为什么表现不同?

DoubleUtil.DoubleToInt(double val)如何工作?

MS.Internal.DoubleUtil包含该函数 public static int DoubleToInt(double val) { return (0 < val) ? (int)(val + 0.5) : (int)(val – 0.5); } 我想知道为什么这个’将’转换为整数?