本文介绍了C#中二进制变量的并集和统一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我为C#中的二进制变量的并集和统一编写了这段代码,但是当我运行它时,控制台只是打开和关闭.有什么问题吗?
Hi All,
I write this code for union and unity of binary variable in C# but when I run it, the console just open and close. what is its problem?
<pre lang="cs">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}
public class CBoolOperate
{
int[] a = null;
int[] b = null;
int[] c = null;
CBoolOperate()//default constructor
{
}
~CBoolOperate()//default destructor
{
}
public void get()
{
Console.WriteLine("please enter first 5 binary digit\n");
for (int i = 0; i < 5; i++)
{
a[i] = Console.Read();
}
Console.WriteLine("please enter first 5 binary digit\n");
for (int i = 0; i < 5; i++)
{
b[i] = Console.Read();
}
}
public void union()//A member function
{
for (int i = 0; i < 5; i++)
{
if (a[i] == 1 || b[i] == 1) c[i] = 1;
else c[i] = 0;
Console.WriteLine(c[i]);
}
Console.WriteLine("");
}
public void and()//A member function
{
for (int i = 0; i < 5; i++)
{
if (a[i] == 1 && b[i] == 1) c[i] = 1;
else c[i] = 0;
Console.WriteLine(c[i]);
}
Console.WriteLine("");
}
public int main()
{
CBoolOperate r=new CBoolOperate();
r.get();
r.union();
r.and();
return 0;
}
}
请帮我.
在此先感谢.
Please help me.
Thanks in Advance.
推荐答案
public CBoolOperate()//default constructor
{
}
and
static void Main(string[] args)
{
CBoolOperate A = new CBoolOperate();
A.main();
Console.ReadLine();
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
CBoolOperate.main();
Console.ReadLine();
}
}
}
public class CBoolOperate
{
int[] a = null;
int[] b = null;
int[] c = null;
CBoolOperate()//default constructor
{
}
~CBoolOperate()//default destructor
{
}
public void get()
{
this.a = new int[5];
this.b = new int[5];
this.c = new int[5];
Console.WriteLine("please enter first 5 binary digit\n");
for (int i = 0; i < 5; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("please enter first 5 binary digit\n");
for (int i = 0; i < 5; i++)
{
b[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void union()//A member function
{
Console.WriteLine("result of union for numbers");
for (int i = 0; i < 5; i++)
{
if (a[i] == 1 || b[i] == 1) c[i] = 1;
else c[i] = 0;
Console.WriteLine(c[i]);
}
Console.WriteLine("");
}
public void and()//A member function
{
Console.WriteLine("result of and for numbers");
for (int i = 0; i < 5; i++)
{
if (a[i] == 1 && b[i] == 1) c[i] = 1;
else c[i] = 0;
Console.WriteLine(c[i]);
}
Console.WriteLine("");
}
public static int main()
{
CBoolOperate r=new CBoolOperate();
r.get();
r.union();
r.and();
return 0;
}
}
这篇关于C#中二进制变量的并集和统一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!