小编ven*_*rik的帖子

动态创建可为空的类型

我需要将Type变量设置为可为空的变量。例如

public Type CreateNullable(Type type){
    if (type.IsValueType)
        return Nullable<type>;

    // Is already nullable
    return type;
}
Run Code Online (Sandbox Code Playgroud)

我看到的是ValueType数量有限,我想我将创建一个所有值类型都可以为null的Dictionary,然后将其返回。但是我很想看看是否有更聪明的方法。

c#

1
推荐指数
2
解决办法
469
查看次数

如何检查MediaElement是否已停止?

如果MediaElement暂时停止或播放,我需要检查.这是我的代码:

private void PlayAudioClick(object sender, RoutedEventArgs e)
{
    AudioPlayer.Play();
    StopAudio.Visibility = Visibility.Visible;
    PlayAudio.Visibility = Visibility.Collapsed;
    if (AudioPlayer.Stoped == true)
    {
        PlayAudio.Visibility = Visibility.Visible;
        StopAudio.Visibility = Visibility.Collapsed;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在寻找像这样的伪代码:if(AudioPlayer.Stoped == true){//做某事}.

c# xaml mediaelement windows-phone-8

1
推荐指数
1
解决办法
5710
查看次数

如果值存在则更新,否则在数据库中插入值

我有一个问题,如果我的4中的值textbox- 房间类型,房间类型,费率,额外费用; 如果数据库中存在"房间类型",则更新,如果不存在,则插入到数据库.

public void existRoomType()
{
    con.Open();
    string typetable = "tblRoomType";
    string existquery = "SELECT*FROM tblRoomType WHERE RoomType = '" + txtRoomType.Text + "'";
    da = new SqlDataAdapter(existquery, con);
    da.Fill(ds, typetable);
    int counter = 0;
    if (counter < ds.Tables[typetable].Rows.Count)
    {
        cmd.Connection = con;
        string edittypequery = "UPDATE tblRoomType SET RoomType = '" + txtRoomType.Text + "', RoomRate = '" + txtRateOfRoom.Text + "', ExtraCharge = '" + txtExtraCharge.Text + "', CancelFee = '" + txtCancelFee.Text + "', …
Run Code Online (Sandbox Code Playgroud)

c# sql-server if-statement sql-update sql-insert

1
推荐指数
1
解决办法
1024
查看次数

如何使用毕加索或通用图像加载器和列表视图

从互联网文本数据加载并链接到图像.我无法理解如何在listview中加载图像.阅读,它需要使用毕加索或通用图像加载器,但不明白如何.请更正我的代码

    public class JsonReadTask extends AsyncTask<String, Void, String> {

      @Override
      protected String doInBackground(String... params) {
       HttpClient httpclient = new DefaultHttpClient();
       HttpPost httppost = new HttpPost(params[0]);
       try {
        HttpResponse response = httpclient.execute(httppost);
        jsonResult = inputStreamToString(
          response.getEntity().getContent()).toString();
       }

       catch (ClientProtocolException e) {
        e.printStackTrace();
       } catch (IOException e) {
        e.printStackTrace();
       }
       return null;
      }

      private StringBuilder inputStreamToString(InputStream is) {
       String rLine = "";
       StringBuilder answer = new StringBuilder();
       BufferedReader rd = new BufferedReader(new InputStreamReader(is));

       try {
        while ((rLine = rd.readLine()) != null) { …
Run Code Online (Sandbox Code Playgroud)

android universal-image-loader picasso

0
推荐指数
1
解决办法
5843
查看次数

可以实现多种设计模式吗?

I'm currently developing a school project and we are instructed that we are required to implement Object-Oriented Programming concepts in our software. But I don't want to implement it just by simply inheriting this class to that class and overriding this method to implement its own functionality and so on. Though it is still acceptable but I want to do it differently. By differently, I mean by using design patterns. I'm trying to understand it one by one and I …

oop design-patterns

0
推荐指数
1
解决办法
949
查看次数

如果用户输入不是数字

这是一个非常简单的脚本,我想弄清楚,我一直在寻找一个简单的答案,无法在论坛或我的C#书中找到它.

Console.Write("Enter a Number\n");
int input = Convert.ToInt32(Console.ReadLine()); //convert code to an integer

if (!Int32.IsNumber(input)) //if not a whole number input give an error
{
    Console.WriteLine("Not an integer");
}
Run Code Online (Sandbox Code Playgroud)

这就是我想要做的那么简单.这是一个更大代码的片段.

c# string integer converter

0
推荐指数
1
解决办法
2万
查看次数