Tag: 方法

将classname作为返回类型的方法

我是c#或任何类型的编程语言的新手。 当我在c#中看到代码时,发现有很多混淆在这里。 其中一个我想从这里澄清一下。 方法常见的结构是 () { //do any thing return ; } 在上面的例子中,我多次在使用 , 等,但很自然这些也是用户定义的类型。 所以这也应该在这里。 但是,当我们使用“类名”代替字符串或任何数据类型时,从来没有站在这里发生的事情? 请用简单的文字和简单的例子让我理解这一点。 class StockData { public int StockID { get; set; }; public double CurrentPrice { get; set; }; public string StockName { get; set; }; } class GetStock { public StockData /*(this is the same name which is […]

将Array转换为主要方法以表示相同的结果,不使用仅LINQ int。

我的程序记录了四个房间在瓶子里收集的瓶子数量。 当用户输入退出时,显示每个房间收集的瓶子数量,并打印出具有最多瓶子的房间。 我用一个数组来跟踪房间号码。 如何更改方法而不是使用数组,我想启动room1,room2,room3,room4。 如果我不使用数组,我是否可以使用我的循环数组调用来写行? 我的意思是。 int room = int.Parse(quit); Console.Write(“Bottles collected in room {0}: “, room); // This line adds the count of bottles and records it so you can continuously count the bottles collected. rooms[room – 1] += int.Parse(Console.ReadLine()); 而这一行: }//Writes the bottles collected by the different rooms Console.WriteLine(“Bottles collected in room {0} […]

如何在C#中使用派生返回类型覆盖方法?

我想用派生类类型覆盖虚方法。 目前最好的方法是什么? 到目前为止,我发现了两种方法: 为每个派生类型使用abstract基class ; 桥接与protected方法。 使用带有public访问器的protected实现。 基本情况(没有实现解决方案, Clone总是返回基类型A1 ): public class A1 { public int X1 { get; set; } public A1(int x1) { this.X1 = x1; } public virtual A1 Clone() { return new A1(X1); } } public class A2 : A1 { public int X2 { get; set; } public A2(int x1, […]

如何从另一个类更改标签? c#windows形成视觉工作室

我知道有很multithreading在谈论这个并相信我,我已经看到了所有这些,但我认为我有点慢,无法弄清楚如何做到这一点,所以这就是事情! 我有一个表格 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button4_Click(object sender, EventArgs e) { adi mYadi= new adi(); adi.paso(); } private void Form1_Load(object sender, EventArgs e) { } public void l8u(string l ) { label8.Text = l; } } l8u方法应该更改label8的文本,因此它不能是静态的,因为label8不是静态的(是公共的)而且我有另外这个类 public class adi :instrucion { private int paso; […]

‘XDevkit.IXboxDebugTarget.GetMemory(uint,uint,byte ,out uint)’的最佳重载方法匹配有一些无效的参数

错误可以在代码下面找到! 基本代码: XDevkit.IXboxDebugTarget.GetMemory(uint, uint, byte[], out uint) 我有什么新的 : uint num1; uint num2; uint num4; num1 = Convert.ToUInt32(textBox2.Text); num2 = Convert.ToUInt32(textBox3.Text); num4 = Convert.ToUInt32(textBox5.Text); byte[] num3; num3 = BitConverter.GetBytes(Convert.ToInt32(textBox3.Text)); IXboxManager xbm = new XboxManager(); IXboxConsole xbc = xbm.OpenConsole(“textBox1.Text”); //Or Console Name in “” IXboxDebugTarget xdt = xbc.DebugTarget; xdt.ConnectAsDebugger(“XeDevMemPatcher”, XboxDebugConnectFlags.Force); // this isn’t always needed IXboxDebugTarget.GetMemory(num1, […]

委托和界面如何可以互换使用?

我可以使用接口方法而不是委托吗? 怎么样? 我发现搜索接口方法比使用委托更快。 我会很感激一个简单的代码片段。

generics方法重载的问题

我有以下方法: void s(int a, tb) { … .. . } void s(int a, int b) { … .. . } void s(int a, long b) { … .. . } 当我想用它作为s(10,10)我在工具提示中看到了这些覆盖。 s(int a,int b); 和 s(int a,long b); 。 但是,我想我必须看到s(int a,long b); 。 怎么了 ? 我有visual studio 2008 sp1 。 谢谢 更新:我在Visual Studio 2010中测试过它。结果是一样的。 更新:它似乎是关于c#而不是visual […]

textBox1.Text.Insert(…)方法不起作用

我正面临这种不正常的情况。 以下代码无法正常运行: string temp = “heythere”; Console.WriteLine(temp); temp.Insert(3, “hello”); Console.WriteLine(temp); 是不是应该输出像“heyhellothere”? 但它确实“heyrehere”(没有变化)。

使用可选参数和命名参数解决歧义

我的项目有两种方法,如下所示: void Person(int ID, double height = 0.0, string team = “Knights”) { //my codes } void Person(int ID, double height = 0.0, string team = “Knights”, int age = 30) { //my codes } 这是我调用方法的地方: Person(1, 2.5, “Dark Ghost”); //calls first method 我在构建项目时没有遇到任何错误但是我很困惑为什么上面调用第一个方法? 并且: Person(1, 46.5); //compiler error.

从C ++ DLL(使用“Dllimport”从C#加载)调用C#方法/函数

在单个标题中恢复它有点困难,所以在这里我的情况。 我正在构建一个加载C ++库的C#应用​​程序。 我从该C ++ DLL调用函数。 但我也喜欢我的C ++ DLL从C#应用程序调用函数(即导入/运行它)… 这里有一段代码使它更全面: // I’m importing functions from my native code [DllImport(dllFilePath, CallingConvention = CallingConvention.Cdecl)] public static extern int returnIntValue(int value); [DllImport(dllFilePath, CallingConvention = CallingConvention.Cdecl)] public static extern int returnIntArrValueAt(int[] values, int index); // Here is the kind of code it should be // [DllImport(dllFilePath, CallingConvention = CallingConvention.Cdecl)] […]