c++ - How to define constructor outside the class in c# -
i new c# , switched c++ c#. doing in c++:
class { public : a(char *argv);//declaration of constructor }
then in main doing this:
int main(int argc, char **argv) { obj(argv[1]); }
then definition of constructor :
a::a(char * argv) { //here use command line argument argv contains file. }
i tried write equivalent code in c# follows:
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 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
the couple of errors got ://i have indicated line corresponding errors in code
shekhar_c#.cs(16,25): error cs1525: unexpected symbol `huffman', expecting `class', `delegate', `enum', `interface', `partial', or `struct' shekhar_c#.cs(18,33): error cs1530: keyword `new' not allowed on namespace elements shekhar_c#.cs(18,36): error cs1525: unexpected symbol `binaryreader', expecting `class', `delegate', `enum', `interface', `partial', or `struct' shekhar_c#.cs(18,79): warning cs0658: `value' invalid attribute target. attributes in attribute section ignored shekhar_c#.cs(34,1): error cs8025: parsing error compilation failed: 4 error(s), 1 warnings
could please me in writing c# equivalent of c++ (removing these errors). guidance welcome because beginner c#.
c# requires constructors defined within class:
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 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
Comments
Post a Comment