C# 如何在c中定义类外的构造函数# 我是C语言的新手,刚从C++转为C语言。 我在用c++做类似的事情: Class A { public : A(char *argv);//declaration of constructor }
然后大体上我是这样做的:C# 如何在c中定义类外的构造函数# 我是C语言的新手,刚从C++转为C语言。 我在用c++做类似的事情: Class A { public : A(char *argv);//declaration of constructor },c#,c++,C#,C++,然后大体上我是这样做的: int main(int argc, char **argv) { A Obj(argv[1]); } 那么构造函数的定义我是这样做的: A::A(char * argv) { //Here i use this command line argument argv which contains a file. } 我尝试用c#编写等效代码,如下所示: using System; using System.IO; using System.Collectio
int main(int argc, char **argv)
{
A Obj(argv[1]);
}
那么构造函数的定义我是这样做的:
A::A(char * argv)
{
//Here i use this command line argument argv which contains a file.
}
我尝试用c#编写等效代码,如下所示:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace shekhar_final
{
class Huffman
{
public int data_size,length,i,is_there, total_nodes;
string code;
Huffman(char *args);
}
public Huffman(char *args) //called from MyClass Line:16
{
using (var stream = new BinaryReader(System.IO.File.OpenRead(args[0]))) //Line : 18
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
public class MyClass
{
public static void Main(string[] args)
{
Huffman ObjSym =new Huffman(args);//object creation
}
}
}// Line:34
请您帮助我写C++中的C等价物(除去这些错误)。由于我是c#的初学者,所以也欢迎额外的指导 在C#中没有提前定义方法——它们是在类本身中定义的。请尝试以下方法:
class Huffman
{
public int data_size,length,i,is_there, total_nodes;
string code;
public Huffman(char *args) //called from MyClass Line:16
{
using (var stream = new BinaryReader(System.IO.File.OpenRead(args[0]))) //Line : 18
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
}
public class MyClass
{
public static void Main(string[] args)
{
Huffman ObjSym =new Huffman(args); //Here is the error
}
}
哈夫曼类
{
公共int数据的大小,长度,i,是否存在,总节点数;
字符串代码;
public Huffman(char*args)//从MyClass行调用:16
{
使用(var stream=newbinaryreader(System.IO.File.OpenRead(args[0]))//行:18
{
while(stream.BaseStream.Positionclass Huffman
{
public int data_size,length,i,is_there, total_nodes;
string code;
public Huffman(char *args) //called from MyClass Line:16
{
using (var stream = new BinaryReader(System.IO.File.OpenRead(args[0]))) //Line : 18
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
}
public class MyClass
{
public static void Main(string[] args)
{
Huffman ObjSym =new Huffman(args); //Here is the error
}
}
哈夫曼类
{
公共int数据的大小,长度,i,是否存在,总节点数;
字符串代码;
public Huffman(char*args)//从MyClass行调用:16
{
使用(var stream=newbinaryreader(System.IO.File.OpenRead(args[0]))//行:18
{
while(stream.BaseStream.Position不同于C++,在这里您可以选择组合声明和头部中成员函数的定义,或者将声明放入头文件中并在CPP文件中实现,在C语言中没有这样的选择:如果函数具有体(即它不是抽象的),则主体需要声明:
class Huffman
{
public int data_size,length,i,is_there, total_nodes;
string code;
Huffman(string args) {
using (var stream = new BinaryReader(System.IO.File.OpenRead(args)))
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
}
哈夫曼类
{
公共int数据的大小,长度,i,是否存在,总节点数;
字符串代码;
哈夫曼(字符串args){
使用(var stream=newbinaryreader(System.IO.File.OpenRead(args)))
{
while(stream.BaseStream.Position不同于C++,在这里您可以选择组合声明和头部中成员函数的定义,或者将声明放入头文件中并在CPP文件中实现,在C语言中没有这样的选择:如果函数具有体(即它不是抽象的),则主体需要声明:
class Huffman
{
public int data_size,length,i,is_there, total_nodes;
string code;
Huffman(string args) {
using (var stream = new BinaryReader(System.IO.File.OpenRead(args)))
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
}
哈夫曼类
{
公共int数据的大小,长度,i,是否存在,总节点数;
字符串代码;
哈夫曼(字符串args){
使用(var stream=newbinaryreader(System.IO.File.OpenRead(args)))
{
while(stream.BaseStream.Positionnamespace shekhar_final
{
class Huffman
{
public int DataSize {get; set;}
public int Length {get; set;}
public int I {get;set;}
public int IsThere {get;set;}
public int TotalNodes {get;set;}
private string code;
public Huffman(string[] args) //called from MyClass Line:16
{
using (var stream = new BinaryReader(System.IO.File.OpenRead(args[0]))) //Line : 18
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
}
public class MyClass
{
public static void Main(string[] args)
{
Huffman objSym = new Huffman(args);//object creation
}
}
}// Line:34
namespace shekhar_final
{
哈夫曼班
{
公共int数据大小{get;set;}
公共整数长度{get;set;}
公共整数I{get;set;}
公共int是{get;set;}
公共整数TotalNodes{get;set;}
私有字符串码;
public Huffman(string[]args)//从MyClass行调用:16
{
使用(var stream=newbinaryreader(System.IO.File.OpenRead(args[0]))//行:18
{
while(stream.BaseStream.Position
在C#中,声明和实现是同时进行的:
namespace shekhar_final
{
class Huffman
{
public int DataSize {get; set;}
public int Length {get; set;}
public int I {get;set;}
public int IsThere {get;set;}
public int TotalNodes {get;set;}
private string code;
public Huffman(string[] args) //called from MyClass Line:16
{
using (var stream = new BinaryReader(System.IO.File.OpenRead(args[0]))) //Line : 18
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
}
public class MyClass
{
public static void Main(string[] args)
{
Huffman objSym = new Huffman(args);//object creation
}
}
}// Line:34
namespace shekhar_final
{
哈夫曼班
{
公共int数据大小{get;set;}
公共整数长度{get;set;}
公共整数I{get;set;}
公共int是{get;set;}
公共整数TotalNodes{get;set;}
私有字符串码;
public Huffman(string[]args)//从MyClass行调用:16
{
使用(var stream=newbinaryreader(System.IO.File.OpenRead(args[0]))//行:18
{
while(stream.BaseStream.Position
C#要求在类中定义构造函数:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace shekhar_final
{
public class Huffman{
public int data_size,length,i,is_there, total_nodes;
string code;
public Huffman(string[] args) //called from MyClass Line:16
{
using (var stream = new BinaryReader(System.IO.File.OpenRead(args[0]))) //Line : 18
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte processingValue = stream.ReadByte();
}
}
}
}
public class MyClass
{
public static void Main(string[] args)
{
Huffman ObjSym =new Huffman(args);//object creation
}
}
}// Line:34
使用系统;
使用System.IO;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
谢哈鲁决赛
{
公共级哈夫曼{
公共int数据的大小,长度,i,是否存在,总节点数;
字符串代码;
公众的